95require
'main.inc.php';
96require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
97require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
100$action =
GETPOST(
'action',
'aZ09');
101$original_file =
GETPOST(
'file',
'alphanohtml');
102$hashp =
GETPOST(
'hashp',
'aZ09');
103$modulepart =
GETPOST(
'modulepart',
'alpha');
104$urlsource =
GETPOST(
'urlsource',
'alpha');
105$entity =
GETPOST(
'entity',
'int') ?
GETPOST(
'entity',
'int') : $conf->entity;
108if (empty($modulepart) && empty($hashp)) {
111if (empty($original_file) && empty($hashp)) {
114if ($modulepart ==
'fckeditor') {
115 $modulepart =
'medias';
119if ($user->socid > 0) {
120 $socid = $user->socid;
124if (in_array($modulepart, array(
'facture_paiement',
'unpaid'))) {
125 if (!$user->hasRight(
'societe',
'client',
'voir') || $socid) {
126 $original_file =
'private/'.$user->id.
'/'.$original_file;
146 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
148 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
150 $tmp = explode(
'/', $ecmfile->filepath, 2);
152 if (is_numeric($tmp[0])) {
153 $tmp = explode(
'/', $tmp[1], 2);
155 $moduleparttocheck = $tmp[0];
158 if ($moduleparttocheck == $modulepart) {
160 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
166 $modulepart = $moduleparttocheck;
167 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
169 $entity = $ecmfile->entity;
170 if ($entity != $conf->entity) {
171 $conf->entity = $entity;
172 $conf->setValues($db);
175 $langs->load(
"errors");
182if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
185if (isset($_GET[
"attachment"])) {
186 $attachment =
GETPOST(
"attachment",
'alpha') ?
true:
false;
188if (!empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) {
193$type =
'application/octet-stream';
195 $type =
GETPOST(
'type',
'alpha');
203 $type =
'application/octet-stream';
207$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
208$original_file = str_replace(
'../',
'/', $original_file);
209$original_file = str_replace(
'..\\',
'/', $original_file);
213if (empty($modulepart)) {
219$accessallowed = $check_access[
'accessallowed'];
220$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
221$fullpath_original_file = $check_access[
'original_file'];
226 $sqlprotectagainstexternals =
'';
229 if ($user->socid > 0) {
230 if ($sqlprotectagainstexternals) {
231 $resql = $db->query($sqlprotectagainstexternals);
233 $num = $db->num_rows($resql);
236 $obj = $db->fetch_object($resql);
237 if ($user->socid != $obj->fk_soc) {
250if (!$accessallowed) {
256if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
257 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
258 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
265$filename = basename($fullpath_original_file);
266$filename = preg_replace(
'/\.noexe$/i',
'', $filename);
269dol_syslog(
"document.php download $fullpath_original_file filename=$filename content-type=$type");
270$fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
273if (!file_exists($fullpath_original_file_osencoded)) {
274 dol_syslog(
"ErrorFileDoesNotExists: ".$fullpath_original_file);
275 print
"ErrorFileDoesNotExists: ".$original_file;
280$hookmanager->initHooks(array(
'document'));
281$parameters = array(
'ecmfile' => $ecmfile,
'modulepart' => $modulepart,
'original_file' => $original_file,
282 'entity' => $entity,
'fullpath_original_file' => $fullpath_original_file,
283 'filename' => $filename,
'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
284$object =
new stdClass();
285$reshook = $hookmanager->executeHooks(
'downloadDocument', $parameters, $object, $action);
287 $errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'').join(
', ', $hookmanager->errors) :
'');
288 dol_syslog(
"document.php - Errors when executing the hook 'downloadDocument' : ".$errors);
289 print
"ErrorDownloadDocumentHooks: ".$errors;
296header(
'Content-Description: File Transfer');
298 header(
'Content-Encoding: '.$encoding);
303 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
305 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
308header(
'Cache-Control: Public, must-revalidate');
309header(
'Pragma: public');
313if (!$attachment && !empty($conf->global->MAIN_USE_EXIF_ROTATION) &&
image_format_supported($fullpath_original_file_osencoded) == 1) {
315 $readfile = !$imgres;
324 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser='', $refname='', $mode='read')
Security check when accessing to a document (used by document.php, viewimage.php and webservices to g...
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.