From ac02450200c3079e451a0c063a7927b0fe9eefb6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 3 Sep 2012 18:01:07 +0200 Subject: [PATCH] New: Can also use attachment=0 as parameter (for test purpose) --- htdocs/document.php | 50 +++++---------------------------------------- 1 file changed, 5 insertions(+), 45 deletions(-) diff --git a/htdocs/document.php b/htdocs/document.php index 90850a1f6cc..c4ddba8cca4 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -75,59 +75,18 @@ if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart'); $type = 'application/octet-stream'; if (GETPOST('type','alpha')) $type=GETPOST('type','alpha'); else $type=dol_mimetype($original_file); -//print 'X'.$type.'-'.$original_file;exit; // Define attachment (attachment=true to force choice popup 'open'/'save as') -// TODO $attachment is already true by default $attachment = true; -// Text files -if (preg_match('/\.txt$/i',$original_file)) { - $attachment = false; -} -//if (preg_match('/\.csv$/i',$original_file)) { $attachment = true; } -//if (preg_match('/\.tsv$/i',$original_file)) { $attachment = true; } -// Documents MS office -//if (preg_match('/\.doc(x)?$/i',$original_file)) { $attachment = true; } -//if (preg_match('/\.dot(x)?$/i',$original_file)) { $attachment = true; } -//if (preg_match('/\.mdb$/i',$original_file)) { $attachment = true; } -//if (preg_match('/\.ppt(x)?$/i',$original_file)) { $attachment = true; } -//if (preg_match('/\.xls(x)?$/i',$original_file)) { $attachment = true; } -// Documents Open office -//if (preg_match('/\.odp$/i',$original_file)) { $attachment = true; } -//if (preg_match('/\.ods$/i',$original_file)) { $attachment = true; } -//if (preg_match('/\.odt$/i',$original_file)) { $attachment = true; } -// Misc -if (preg_match('/\.(html|htm)$/i',$original_file)) { - $attachment = false; -} -//if (preg_match('/\.pdf$/i',$original_file)) { $attachment = true; } -//if (preg_match('/\.sql$/i',$original_file)) { $attachment = true; } -// Images -//if (preg_match('/\.jpg$/i',$original_file)) { $attachment = true; } -//if (preg_match('/\.jpeg$/i',$original_file)) { $attachment = true; } -//if (preg_match('/\.png$/i',$original_file)) { $attachment = true; } -//if (preg_match('/\.gif$/i',$original_file)) { $attachment = true; } -//if (preg_match('/\.bmp$/i',$original_file)) { $attachment = true; } -//if (preg_match('/\.tiff$/i',$original_file)) { $attachment = true; } -// Calendar -//if (preg_match('/\.vcs$/i',$original_file)) { $attachment = true; } -//if (preg_match('/\.ics$/i',$original_file)) { $attachment = true; } -if (GETPOST("attachment")) { - $attachment = true; -} +if (preg_match('/\.txt$/i',$original_file)) $attachment = false; +if (preg_match('/\.(html|htm)$/i',$original_file)) $attachment = false; +if (isset($_GET["attachment"])) $attachment = GETPOST("attachment")?true:false; if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; -//print "XX".$attachment;exit; // Suppression de la chaine de caractere ../ dans $original_file $original_file = str_replace("../","/", $original_file); -// find the subdirectory name as the reference -$refname=basename(dirname($original_file)."/"); - -// Suppression de la chaine de caractere ../ dans $original_file -$original_file = str_replace("../","/", $original_file); - -// find the subdirectory name as the reference +// Find the subdirectory name as the reference $refname=basename(dirname($original_file)."/"); // Security check @@ -525,6 +484,7 @@ if (! file_exists($original_file_osencoded)) header('Content-Description: File Transfer'); if ($encoding) header('Content-Encoding: '.$encoding); if ($type) header('Content-Type: '.$type.(preg_match('/text/',$type)?'; charset="'.$conf->file->character_set_client:'')); +// Add MIME Content-Disposition from RFC 2183 (inline=automatically displayed, atachment=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($original_file));