rtgx

Download súborov cez http protokol

Príklad 1 (php.net, readfile)

$file = 'image.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}

Príklad 2

// URL: blog.red-pill.cz/2007/03/06/zabezpecene-stahovani-souboru/

$file = basename($file);
$filepath = $download_folder.'/'.$file';
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Transfer-Encoding: binary');
header('Content-type: image/jpg'); // konkretny MIME-typ
header('Content-Disposition: attachment; filename='.$file);
readfile($filepath);

Príklad 3 (t3quixplorer 1.7.0)

function main($dir, $item) {		// download file
global $LANG,$CLIENT;

if(!t3quixplorer_div::get_is_file($dir,$item)) t3quixplorer_div::showError($item.": ".$LANG->getLL("error.fileexist"));
if(!t3quixplorer_div::get_show_item($dir, $item)) t3quixplorer_div::showError($item.": ".$LANG->getLL("error.accessfile"));

$abs_item = t3quixplorer_div::get_abs_item($dir,$item);
header('Content-Type: '.(($CLIENT["BROWSER"]=='msie' || $CLIENT["BROWSER"]=='opera')?'application/octetstream':'application/octet-stream'));
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($abs_item));
if($CLIENT["BROWSER"]=='msie') {
header('Content-Disposition: inline; filename="'.$item.'"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
} else {
header('Content-Disposition: attachment; filename="'.$item.'"');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
}

@readfile($abs_item);
exit;
}

Príklad 4 (quixplorer 2.3.2)

function download_item($dir, $item) {		// download file
// Security Fix:
$item=basename($item);

if ((($GLOBALS["permissions"] & 01) != 01)
&& (($GLOBALS["permissions"] & 16) != 16))
show_error($GLOBALS["error_msg"]["accessfunc"] . $GLOBALS["permissions"]);

if(!get_is_file($dir,$item)) show_error($item.": ".$GLOBALS["error_msg"]["fileexist"]);
if(!get_show_item($dir, $item)) show_error($item.": ".$GLOBALS["error_msg"]["accessfile"]);

$abs_item = get_abs_item($dir,$item);
$browser=id_browser();
header('Content-Type: '.(($browser=='IE' || $browser=='OPERA')?
'application/octetstream':'application/octet-stream'));
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($abs_item));
if($browser=='IE') {
header('Content-Disposition: attachment; filename="'.$item.'"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
} else {
header('Content-Disposition: attachment; filename="'.$item.'"');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
}

@readfile($abs_item);
exit;
}

Príklad 5 (naw_securedl 0.2.11)

switch(strtolower($endigung)){
case '.pps':
$contenttypedatei='application/vnd.ms-powerpoint';
break;
case '.doc':
$contenttypedatei='application/msword';
break;
case '.xls':
$contenttypedatei='application/vnd.ms-excel';
break;
case '.jpeg':
$contenttypedatei='image/jpeg';
break;
case '.jpg':
$contenttypedatei='image/jpeg';
break;
case '.jpe':
$contenttypedatei='image/jpeg';
break;
case '.mpeg':
$contenttypedatei='video/mpeg';
break;
case '.mpg':
$contenttypedatei='video/mpeg';
break;
case '.mpe':
$contenttypedatei='video/mpeg';
break;
case '.mov':
$contenttypedatei='video/quicktime';
break;
case '.avi':
$contenttypedatei='video/x-msvideo';
break;
case '.pdf':
$contenttypedatei='application/pdf';
break;
case '.svg':
$contenttypedatei='image/svg+xml';
break;
case '.flv':
$contenttypedatei='video/x-flv';
break;
case '.swf':
$contenttypedatei='application/x-shockwave-flash';
break;
default:
$contenttypedatei='application/octet-stream';
break;
}

header("Pragma: private");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Type: '.$contenttypedatei);
if ($forcedownload == true){
header('Content-Disposition: attachment; filename="'.basename($file).'"');
}else{
header('Content-Disposition: inline; filename="'.basename($file).'"');
}
readfile($file);

Príklad 6 (nf_downloads 1.1.2 - 19.09.2005)

if (file_exists($filePath.$data["filename"])) {
$ext = substr($data["filename"],-3);
switch($ext){
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: $ctype");
$user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
if ((is_integer (strpos($user_agent, "msie"))) && (is_integer (strpos($user_agent, "win")))) {
header("Content-Disposition: filename=".basename($data['filename']).";");
} else {
header("Content-Disposition: attachment; filename=".basename($data['filename']).";");
}
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filePath.$data['filename']));
readfile($filePath.$data['filename']);
} else {
die('ERROR: ...');
}
 
Žiadne dokumenty ani odkazy k tejto stránke.

Generátor typoscriptu

Vytvára typoscript pre bežné použitie. Generátor je jednoduchý na obsluhu, stačí vyplniť zopár položiek formulára.

Odkazy