From 3b6d6eec9afe8aa2cf955c01e55925adb3c7c528 Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Fri, 4 Jan 2019 18:06:54 +0100 Subject: [PATCH] Fix cach on image for website --- htdocs/website/samples/wrapper.html | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/htdocs/website/samples/wrapper.html b/htdocs/website/samples/wrapper.html index fb6a10b1264..32ed05e49c1 100644 --- a/htdocs/website/samples/wrapper.html +++ b/htdocs/website/samples/wrapper.html @@ -1,11 +1,12 @@ entity; $original_file=GETPOST("file","alpha"); @@ -54,17 +55,26 @@ if (! empty($hashp)) // Define attachment (attachment=true to force choice popup 'open'/'save as') $attachment = true; if (preg_match('/\.(html|htm)$/i',$original_file)) $attachment = false; -if (isset($_GET["attachment"])) $attachment = GETPOST("attachment",'alpha')?true:false; -if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; +if (isset($_GET["attachment"])) $attachment = GETPOST("attachment",'none')?true:false; +if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS_WEBSITE)) $attachment=false; // Define mime type $type = 'application/octet-stream'; -if (GETPOST('type','alpha')) $type=GETPOST('type','alpha'); +if (GETPOST('type','none')) $type=GETPOST('type','alpha'); else $type=dol_mimetype($original_file); // Security: Delete string ../ into $original_file $original_file=str_replace("../","/", $original_file); +// Cache or not +if (GETPOST("cache",'none') || image_format_supported($original_file) >= 0) +{ + // Important: Following code is to avoid page request by browser and PHP CPU at + // each Dolibarr page access. + header('Cache-Control: max-age=3600, public, must-revalidate'); + header('Pragma: cache'); // This is to avoid having Pragma: no-cache +} + // Find the subdirectory name as the reference $refname=basename(dirname($original_file)."/"); @@ -110,15 +120,13 @@ else // Permissions are ok and file found, so we return it //top_httphead($type); + header('Content-Type: '.$type); header('Content-Description: File Transfer'); if ($encoding) header('Content-Encoding: '.$encoding); // Add MIME Content-Disposition from RFC 2183 (inline=automatically displayed, attachment=need user action to open) if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); else header('Content-Disposition: inline; filename="'.$filename.'"'); header('Content-Length: ' . dol_filesize($fullpath_original_file)); - // Ajout directives pour resoudre bug IE - header('Cache-Control: Public, must-revalidate'); - header('Pragma: public'); readfile($fullpath_original_file_osencoded); }