各位大大,
在用PHP下載test.zip檔案後,檔案的大小都只有1KB,而且下載後也毁損不能打開,請問是那錯了嗎?
<?php
if(empty($_GET['path']) || empty($_GET['filename']))
{
echo 'error path';
exit();
}
if(file_exists($_GET['path']))
{
$FILEname = urlencode($_GET['filename']);
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
header("Content-Type: application/octetstream; name=$FILEname"); //for IE & Opera
header("Content-Type: application/octet-stream; name=$FILEname"); //for the rest
header("Content-Disposition: attachment; filename=$FILEname;");
header("Content-Transfer-Encoding: binary");
header("Content-Type: application/zip");
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
readfile($_GET['path']);
echo "success";
}
else
echo 'file doesnt exist';
?>