色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php 下載保存文件保存到本地的兩種實現方法

第一種:

<?php 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();?>


<?php 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);?> 

第二種:

<?php function downfile($fileurl){$filename=$fileurl;$file  =  fopen($filename, "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);?>

php實現下載文件的兩種方法。分享下,有用到的朋友看看哦。

方法一:

<?php/*** 下載文件* header函數**/header('Content-Description: File Transfer');header('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename='.basename($filepath));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($filepath));readfile($file_path);?>

了解php中header函數的用法。

方法二:

<?php//文件下載//readfile$fileinfo = pathinfo($filename);header('Content-type: application/x-'.$fileinfo['extension']);header('Content-Disposition: attachment; filename='.$fileinfo['basename']);header('Content-Length: '.filesize($filename));readfile($thefile);exit();?>

php技術php 下載保存文件保存到本地的兩種實現方法,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 大渡口区| 巩留县| 额敏县| 崇明县| 萍乡市| 潼南县| 朝阳县| 永泰县| 晋中市| 海林市| 湖北省| 平邑县| 长葛市| 府谷县| 都兰县| 渭南市| 沁阳市| 定西市| 黄梅县| 深泽县| 海阳市| 玉树县| 盐山县| 手游| 缙云县| 常山县| 静海县| 和平区| 峨山| 应城市| 阜阳市| 涿鹿县| 钟山县| 昆明市| 安岳县| 鄱阳县| 沭阳县| 搜索| 平阴县| 耒阳市| 巴马|