pHP檔案下載代碼,求各位大神給看看那錯哪了

來源:互聯網
上載者:User
pHP檔案下載代碼,求各位大神給看看那哪裡錯了
//檔案下載函數
//$file_path 檔案下載路徑
//$file_name 檔案名稱
//$file_sub_dir 下載檔案子路徑
function down_file($file_name,$file_sub_dir){
//如果檔案名稱字是中文,轉碼
$file_name=iconv("utf-8", "gb-2312", $file_name);
//絕對路徑
$file_path=$_SERVER["DOCUMENT_ROOT"].$file_sub_dir.$file_name;
//開啟檔案
if(!file_exists($file_path)){
echo "檔案不存在!";
return;
}
$fp=fopen($file_path, "r");

//擷取檔案大小
$file_size=filesize($file_path);

//返回的檔案
header("Content-type: application/octet-stream");
//按照位元組大小返回
header("Accept-Ranges: bytes");
//返迴文件大小
header("Accept-length: $file_size");
//用戶端彈出對話方塊,對應的檔案名稱
header("Content-Disposition: attachment; file_name=".$file_name);

//向用戶端回送資料

$buffer=1024;
//為了下載安全,做個檔案位元組讀取技術器
$file_count=0;
//判斷檔案是否結束
while (!feof($fp) && ($file_size-$file_count>0)){
$file_data=fread($fp, $buffer);
//讀取了多少位元組
$file_count+=$buffer;
//把部分資料傳給瀏覽器
echo $file_data;

}
//關閉檔案
fclose($fp);
}
file_down("1.jpg","/test/");
?>
------解決思路----------------------
Warning: fopen(C:/AppServ/www/test/) [function.fopen]: failed to open stream: Permission denied in C:\AppServ\www\test\FileDownServer.php on line 16
說的很明確了!
Permission denied 中文釋義:許可權被拒絕
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.