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

  1. Append &file=<relative path> to the viewimage URL
  2. Or generate a shared link with hashp via ecm file hash (dol_buildHashic / getFileLink using hashp)
  3. For barcode images set modulepart=barcode and pass the code parameters
  4. 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

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


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)