36 if (!defined(
'NOTOKENRENEWAL')) {
37 define(
'NOTOKENRENEWAL',
'1');
39 if (!defined(
'NOREQUIREMENU')) {
40 define(
'NOREQUIREMENU',
'1');
42 if (!defined(
'NOREQUIREHTML')) {
43 define(
'NOREQUIREHTML',
'1');
45 if (!defined(
'NOREQUIREAJAX')) {
46 define(
'NOREQUIREAJAX',
'1');
50 if (isset($_GET[
"hashp"]) && !defined(
"NOLOGIN")) {
51 if (!defined(
"NOLOGIN")) {
54 if (!defined(
"NOCSRFCHECK")) {
55 define(
"NOCSRFCHECK", 1);
57 if (!defined(
"NOIPCHECK")) {
58 define(
"NOIPCHECK", 1);
62 if ((isset($_GET[
"modulepart"]) && $_GET[
"modulepart"] ==
'medias')) {
63 if (!defined(
"NOLOGIN")) {
66 if (!defined(
"NOCSRFCHECK")) {
67 define(
"NOCSRFCHECK", 1);
69 if (!defined(
"NOIPCHECK")) {
70 define(
"NOIPCHECK", 1);
93 require
'main.inc.php';
94 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
95 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
98 $action =
GETPOST(
'action',
'aZ09');
99 $original_file =
GETPOST(
'file',
'alphanohtml');
100 $hashp =
GETPOST(
'hashp',
'aZ09');
101 $modulepart =
GETPOST(
'modulepart',
'alpha');
102 $urlsource =
GETPOST(
'urlsource',
'alpha');
103 $entity =
GETPOST(
'entity',
'int') ?
GETPOST(
'entity',
'int') : $conf->entity;
106 if (empty($modulepart) && empty($hashp)) {
109 if (empty($original_file) && empty($hashp)) {
112 if ($modulepart ==
'fckeditor') {
113 $modulepart =
'medias';
117 if ($user->socid > 0) {
118 $socid = $user->socid;
122 if (in_array($modulepart, array(
'facture_paiement',
'unpaid'))) {
123 if (!$user->hasRight(
'societe',
'client',
'voir') || $socid) {
124 $original_file =
'private/'.$user->id.
'/'.$original_file;
143 if (!empty($hashp)) {
144 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
146 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
148 $tmp = explode(
'/', $ecmfile->filepath, 2);
150 if (is_numeric($tmp[0])) {
151 $tmp = explode(
'/', $tmp[1], 2);
153 $moduleparttocheck = $tmp[0];
156 if ($moduleparttocheck == $modulepart) {
158 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
164 $modulepart = $moduleparttocheck;
165 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
167 $entity = $ecmfile->entity;
168 if ($entity != $conf->entity) {
169 $conf->entity = $entity;
170 $conf->setValues($db);
173 $langs->load(
"errors");
180 if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
183 if (isset($_GET[
"attachment"])) {
184 $attachment =
GETPOST(
"attachment",
'alpha') ?
true:
false;
186 if (!empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) {
191 $type =
'application/octet-stream';
192 if (
GETPOST(
'type',
'alpha')) {
193 $type =
GETPOST(
'type',
'alpha');
201 $type =
'application/octet-stream';
205 $original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
206 $original_file = str_replace(
'../',
'/', $original_file);
207 $original_file = str_replace(
'..\\',
'/', $original_file);
211 $refname = basename(dirname($original_file).
"/");
214 if (empty($modulepart)) {
220 $accessallowed = $check_access[
'accessallowed'];
221 $sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
222 $fullpath_original_file = $check_access[
'original_file'];
225 if (!empty($hashp)) {
227 $sqlprotectagainstexternals =
'';
230 if ($user->socid > 0) {
231 if ($sqlprotectagainstexternals) {
232 $resql = $db->query($sqlprotectagainstexternals);
234 $num = $db->num_rows(
$resql);
237 $obj = $db->fetch_object(
$resql);
238 if ($user->socid != $obj->fk_soc) {
251 if (!$accessallowed) {
257 if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
258 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
259 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
266 $filename = basename($fullpath_original_file);
267 $filename = preg_replace(
'/\.noexe$/i',
'', $filename);
270 dol_syslog(
"document.php download $fullpath_original_file filename=$filename content-type=$type");
271 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
274 if (!file_exists($fullpath_original_file_osencoded)) {
275 dol_syslog(
"ErrorFileDoesNotExists: ".$fullpath_original_file);
276 print
"ErrorFileDoesNotExists: ".$original_file;
281 if (!is_object($hookmanager)) {
282 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
285 $hookmanager->initHooks(array(
'document'));
286 $parameters = array(
'ecmfile' => $ecmfile,
'modulepart' => $modulepart,
'original_file' => $original_file,
287 'entity' => $entity,
'refname' => $refname,
'fullpath_original_file' => $fullpath_original_file,
288 'filename' => $filename,
'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
289 $reshook = $hookmanager->executeHooks(
'downloadDocument', $parameters);
291 $errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'').join($separator, $hookmanager->errors) :
'');
292 dol_syslog(
"document.php - Errors when executing the hook 'downloadDocument' : ".$errors);
293 print
"ErrorDownloadDocumentHooks: ".$errors;
299 header(
'Content-Description: File Transfer');
301 header(
'Content-Encoding: '.$encoding);
305 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
307 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
310 header(
'Cache-Control: Public, must-revalidate');
311 header(
'Pragma: public');
315 if (!$attachment && !empty($conf->global->MAIN_USE_EXIF_ROTATION) &&
image_format_supported($fullpath_original_file_osencoded) == 1) {
317 $readfile = !$imgres;
320 if (is_object($db)) {
326 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
Class to manage ECM files.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(isset($_GET["hashp"]) &&!defined("NOLOGIN")) if((isset($_GET["modulepart"]) && $_GET["modulepart"]=='medias')) llxHeader()
Header empty.
dol_filesize($pathoffile)
Return size of a 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...
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
dolIsAllowedForPreview($file)
Return if a file is qualified for preview.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
correctExifImageOrientation($fileSource, $fileDest, $quality=95)
Add exif orientation correction for image.
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
$conf db
API class for accounts.