phpはファイルのダウンロードの実例を実現して共有します。


例を挙げます

<?php
class Downfile {

    function downserver($file_name){
$file_path = "./img/".$file_name;
// , gb2312
$file_name = iconv("utf-8","gb2312",$file_name);
$file_path = iconv("utf-8","gb2312",$file_path);
$fp = fopen($file_path,"r") or exit(" ");
//
$buffer = 1024;
//
$file_size = filesize($file_path);
//header("Content-type:text/html;charset=gb2312");
// http
header("Content-type:application/octet-stream");
header("Accept-Ranges:bytes");//
header("Content-Length: ".$file_size);// Accept-Length http
header("Content-Disposition:attachment;filename=".$file_name);
// ,
$count = 0;
while(!feof($fp) && $file_size-$count>0){
// $fp $buffer
$file_data = fread($fp,$buffer);
$count+=$buffer;
//
echo $file_data;
}
//
fclose($fp);
    }

   }
?>
この関数を呼び出してファイル名を入力するとファイルのダウンロードができますが、ファイルの修正に注意してください。パス