ホームページ  >  記事  >  バックエンド開発  >  PHP を実装してファイルを local_PHP にダウンロードおよび保存する 2 つの方法チュートリアル

PHP を実装してファイルを local_PHP にダウンロードおよび保存する 2 つの方法チュートリアル

WBOY
WBOYオリジナル
2016-07-21 14:59:00793ブラウズ

第一种:

复制代码代码如下:

function downfile()
{
$filename=realpath("resume.html");  //文件名
$date=date("Ymd-H:i:m");
Header( "Content-type: application/octet-stream ");
Header( "Accept-Ranges: bytes ");
Header( "Accept-Length: " .filesize($filename));
header( "Content-Disposition: attachment; filename= {$date}.doc");
echo file_get_contents($filename);
readfile($filename);
}
downfile();
?>

または
复制代码代码如下:

function downfile($fileurl)
{
ob_start();
$filename=$fileurl;
$date=date("Ymd-H:i:m");
header( "Content-type: application/octet-stream ");
header( "Accept-Ranges: bytes ");
header( "Content-Disposition: attachment; filename= {$date}.doc");
$size=readfile($filename);
header( "Accept-Length: " .$size);
}
$url="url地址";
downfile($url);
?>

第二种:
复制代代码如下:

function downfile($fileurl)
{
$filename=$fileurl;
$file = fopen ($ファイル名、「rb」);
Header( "Content-type: application/octet-stream ");
Header( "Accept-Ranges: bytes ");
Header( "Content-Disposition: attachment; filename= 4.doc");
$contents = "";
while (!feof($file)) {
$contents .= fread($file, 8192);
}
echo $contents;
fclose($file);
}
$url="url地址";
downfile($url);
?>

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/328180.html技術記事最初のタイプ: 复制代码 代码如下: ?php function downfile() { $filename=realpath("resume.html"); //文件名 $date=date("Ymd-H:i:m"); Header( "Content-type: application/octet-...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。