{"record":{"id":"e9a53b6a16959f88","repo":"Dolibarr/dolibarr","slug":"errorfiledoesnotexists-original-file","errorCode":null,"errorMessage":"ErrorFileDoesNotExists : ${original_file}","messagePattern":"ErrorFileDoesNotExists : (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"htdocs/document.php","lineNumber":356,"sourceCode":"\tdol_syslog(\"Refused to deliver file \".$fullpath_original_file);\n\tprint \"ErrorFileNameInvalid: \".dol_escape_htmltag($original_file);\n\texit;\n}\n\n\nclearstatcache();\n\n$filename = basename($fullpath_original_file);\n$filename = preg_replace('/\\.noexe$/i', '', $filename);\n\n// Output file on browser\ndol_syslog(\"document.php download $fullpath_original_file filename=$filename content-type=$type\");\n$fullpath_original_file_osencoded = dol_osencode($fullpath_original_file); // New file name encoded in OS encoding charset\n\n// This test if file exists should be useless. We keep it to find bug more easily\nif (!file_exists($fullpath_original_file_osencoded)) {\n\tdol_syslog(\"ErrorFileDoesNotExists: \".$fullpath_original_file);\n\tprint $langs->trans(\"ErrorFileDoesNotExists\") . ' : ' . dol_escape_htmltag($original_file);\n\texit;\n}\n\n// Hooks\n$hookmanager->initHooks(array('document'));\n$parameters = array('ecmfile' => $ecmfile, 'modulepart' => $modulepart, 'original_file' => $original_file,\n\t'entity' => $entity, 'fullpath_original_file' => $fullpath_original_file,\n\t'filename' => $filename, 'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);\n$object = new stdClass();\n$reshook = $hookmanager->executeHooks('downloadDocument', $parameters, $object, $action); // Note that $action and $object may have been\nif ($reshook < 0) {\n\t$errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ? ', ' : '').implode(', ', $hookmanager->errors) : '');\n\tdol_syslog(\"document.php - Errors when executing the hook 'downloadDocument' : \".$errors);\n\tprint \"ErrorDownloadDocumentHooks: \".$errors;\n\texit;\n}\n\n// Set this for test","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/Dolibarr/dolibarr/blob/598aa4bdada683d17ca04b1842548821ff0eb6c6/htdocs/document.php#L338-L374","documentation":"After resolving the file path, document.php checks file_exists() on the OS-encoded full path and, when the file is missing, prints the localized 'ErrorFileDoesNotExists : <file>' and exits. It is a defensive existence check before streaming the file from htdocs/document.php:353-357.","triggerScenarios":"Request to document.php where the composed path $fullpath_original_file_osencoded does not exist on disk: wrong modulepart, wrong original_file, file deleted/moved, wrong entity/multicompany dir, or filesystem encoding mismatch between UTF-8 name and OS encoding.","commonSituations":"Files removed by cleanup jobs while links persist; multicompany setups pointing at the wrong entity directory; documents stored on external storage not mounted; non-ASCII filenames saved with a different charset than the OS locale.","solutions":["Verify the file actually exists at DOL_DATA_ROOT/<modulepart>/... for the given entity","Check modulepart and original_file parameters match how the file was stored (list the dir with ls)","Check multicompany entity configuration — the path depends on $conf->entity","Fix OS locale/charset (dol_osencode) if the filename contains non-ASCII characters","Regenerate the link, ideally using the hashp shared-link parameter which resolves via llx_ecm_files"],"exampleFix":"// before\n$file = $conf->facture->dir_output.'/'.$facid.'/pdf.pdf'; // guessed path\n// after\ninclude_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';\nif (!dol_is_file($file)) { setEventMessages('FileMissing: '.$file, null, 'errors'); }","handlingStrategy":"validation","validationCode":"$path = dol_osencode($fullpath); if (!is_file($path)) { die('File missing: '.$fullpath); }","typeGuard":"function fileExists(string $fullpath): bool { return is_file(dol_osencode($fullpath)); }","tryCatchPattern":null,"preventionTips":["Check dol_is_file() before generating download links","Keep links in sync with the storage: regenerate links after migrations/cleanup jobs","Verify entity/multicompany directory matches the link's context","Use ASCII-safe or properly encoded filenames consistent with OS locale"],"tags":["file-download","file-not-found","filesystem","dolibarr"],"backgroundTag":"file-not-found","analyzedSha":"598aa4bdada683d17ca04b1842548821ff0eb6c6","analyzedAt":"2026-09-14T11:12:15.309Z","contentChangedAt":"2026-09-14T11:12:15.309Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}