Dolibarr/dolibarr · warning
Bad link. Missing identification to find file (param file…
Error message
Bad link. Missing identification to find file (param file or hashp)
What it means
viewimage.php requires some identification of the file: if original_file (param file) is empty and hashp is empty and modulepart is not 'barcode', it returns 400 'Bad link. Missing identification to find file (param file or hashp)'. The script needs either a module-relative path or an ecm hash to locate the image.
Solutions
- Append &file=<relative path> to the viewimage URL
- Or generate a shared link with hashp via ecm file hash (dol_buildHashic / getFileLink using hashp)
- For barcode images set modulepart=barcode and pass the code parameters
- Fix the caller so the file parameter is not stripped (urlencode it)
Example fix
// before $url = DOL_URL_ROOT.'/viewimage.php?modulepart=medias'; // after $url = DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.urlencode($relativepath);
Defensive patterns
Strategy: validation
Validate before calling
if (empty($file) && empty($hashp) && $modulepart !== 'barcode') { throw new InvalidArgumentException('file or hashp required'); } Prevention
- Forward the file parameter through thumbnail/link builders; urlencode it
- Prefer generated image URL helpers (e.g. showPhoto, dol_print_picture) over manual URLs
- For shared/public images pass hashp instead of file
- Assert parameters exist in integration tests for pages rendering images
When it happens
Trigger: GET viewimage.php?modulepart=medias with no file parameter; file parameter dropped by an URL builder; modulepart=barcode exemption not applying because modulepart is something else; hashp empty string treated as missing.
Common situations: Thumbnail generators calling viewimage without forwarding the file param; broken links after migration to hashp-based URLs; custom code that only passes modulepart assuming a default filename.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Bad link. Bad value for parameter modulepart
- Bad link. Bad value for parameter hashp
- Bad link. File is from another module part.
- ErrorFileNotFoundWithSharedLink
- Error: Using the image wrapper to output a file with a mime…
AI-assisted analysis of Dolibarr/dolibarr@598aa4bdad (2026-09-14).
Data as JSON: /api/errors/3e04862cf7d5bafc.
Report an issue: GitHub.
Appendix: source
Thrown at htdocs/viewimage.php:180
* @var Translate $langs
* @var User $user
*/
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$action = GETPOST('action', 'aZ09');
$original_file = GETPOST('file', 'alphanohtml');
$hashp = GETPOST('hashp', 'aZ09', 1);
$extname = GETPOST('extname', 'alpha', 1);
$modulepart = GETPOST('modulepart', 'alpha', 1);
$urlsource = GETPOST('urlsource', 'alpha');
$entity = ($entity > 0 ? $entity : $conf->entity);
// Security check
if (empty($modulepart) && empty($hashp)) {
httponly_accessforbidden('Bad link. Bad value for parameter modulepart', 400);
}
if (empty($original_file) && empty($hashp) && $modulepart != 'barcode') {
httponly_accessforbidden('Bad link. Missing identification to find file (param file or hashp)', 400);
}
if ($hashp == 'shared') {
httponly_accessforbidden('Bad link. Bad value for parameter hashp', 400);
}
if ($modulepart == 'fckeditor') {
$modulepart = 'medias'; // For backward compatibility
}
/*
* Actions
*/
// None
/*View on GitHub (pinned to 598aa4bdad)