Hello,
I encountered an issue while trying to retrieve attached files of a product via the API, specifically within the getDocumentsListByElement
function of api_documents.class.php
.
The $upload_dir
generated was incorrect, resulting in a 404 error even though a file was indeed attached to the product.
In my case, the generated $upload_dir
was htdocs/documents/produit/bougeoir-1/
, whereas the actual path to the product’s file on the server was htdocs/documents/produit/0/9/390/photos/
.
The $upload_dir
is generated by this line of code:
$upload_dir = $conf->product->multidir_output[$object->entity].‘/’.get_exdir(0, 0, 0, 1, $object, ‘product’);
It appears that the get_exdir
function is not generating the intermediate subdirectories correctly.
As a temporary patch, I modified the code to generate the subdirectories based on the product’s ID:
$id = $object->id;
$upload_dir = $conf->product->multidir_output[$object->entity].‘/’.substr($id, -1).‘/’.substr($id, -2, 1).‘/’.$id.‘/photos’;
This modification successfully generates the correct path for product IDs up to 999. For products with IDs greater than 999, the code would need to be adjusted accordingly.
I wanted to share this issue and my temporary patch with the community in case anyone else encounters the same problem. Additionally, I would like to ask if this could be due to a configuration issue on my end, or if it is a known bug that others have encountered and will be addressed in a future update.
Thank you for your help and support!
Dolibarr version used: 17.0.0