111require
'main.inc.php';
112require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
113require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
116$action =
GETPOST(
'action',
'aZ09');
117$original_file =
GETPOST(
'file',
'alphanohtml');
118$hashp =
GETPOST(
'hashp',
'aZ09');
119$modulepart =
GETPOST(
'modulepart',
'alpha');
120$urlsource =
GETPOST(
'urlsource',
'alpha');
124if (empty($modulepart) && empty($hashp)) {
127if (empty($original_file) && empty($hashp)) {
130if ($modulepart ==
'fckeditor') {
131 $modulepart =
'medias';
135if ($user->socid > 0) {
136 $socid = $user->socid;
140if (in_array($modulepart, array(
'facture_paiement',
'unpaid'))) {
141 if (!$user->hasRight(
'societe',
'client',
'voir')) {
142 $original_file =
'private/'.$user->id.
'/'.$original_file;
162 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
164 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
166 $tmp = explode(
'/', $ecmfile->filepath, 2);
168 if (is_numeric($tmp[0])) {
169 $tmp = explode(
'/', $tmp[1], 2);
171 $moduleparttocheck = $tmp[0];
174 if ($moduleparttocheck == $modulepart) {
176 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
182 $modulepart = $moduleparttocheck;
183 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
185 $entity = $ecmfile->entity;
186 if ($entity != $conf->entity) {
187 $conf->entity = $entity;
188 $conf->setValues($db);
191 $langs->load(
"errors");
198if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
201if (isset($_GET[
"attachment"])) {
202 $attachment =
GETPOST(
"attachment",
'alpha') ?
true:
false;
209$type =
'application/octet-stream';
211 $type =
GETPOST(
'type',
'alpha');
219 $type =
'application/octet-stream';
223$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
224$original_file = str_replace(
'../',
'/', $original_file);
225$original_file = str_replace(
'..\\',
'/', $original_file);
229if (empty($modulepart)) {
235$accessallowed = $check_access[
'accessallowed'];
236$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
237$fullpath_original_file = $check_access[
'original_file'];
242 $sqlprotectagainstexternals =
'';
245 if ($user->socid > 0) {
246 if ($sqlprotectagainstexternals) {
247 $resql = $db->query($sqlprotectagainstexternals);
249 $num = $db->num_rows($resql);
252 $obj = $db->fetch_object($resql);
253 if ($user->socid != $obj->fk_soc) {
266if (!$accessallowed) {
272if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
273 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
274 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
281$filename = basename($fullpath_original_file);
282$filename = preg_replace(
'/\.noexe$/i',
'', $filename);
285dol_syslog(
"document.php download $fullpath_original_file filename=$filename content-type=$type");
286$fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
289if (!file_exists($fullpath_original_file_osencoded)) {
290 dol_syslog(
"ErrorFileDoesNotExists: ".$fullpath_original_file);
291 print
"ErrorFileDoesNotExists: ".dol_escape_htmltag($original_file);
296$hookmanager->initHooks(array(
'document'));
297$parameters = array(
'ecmfile' => $ecmfile,
'modulepart' => $modulepart,
'original_file' => $original_file,
298 'entity' => $entity,
'fullpath_original_file' => $fullpath_original_file,
299 'filename' => $filename,
'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
301$reshook = $hookmanager->executeHooks(
'downloadDocument', $parameters, $object, $action);
303 $errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'').implode(
', ', $hookmanager->errors) :
'');
304 dol_syslog(
"document.php - Errors when executing the hook 'downloadDocument' : ".$errors);
305 print
"ErrorDownloadDocumentHooks: ".$errors;
313header(
'Content-Description: File Transfer');
315 header(
'Content-Encoding: '.$encoding);
320 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
322 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
325header(
'Cache-Control: Public, must-revalidate');
326header(
'Pragma: public');
333 $readfile = !$imgres;
342 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser=null, $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.