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

php 下載保存文件保存到本地的兩種實(shí)現(xiàn)方法

第一種:

<?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實(shí)現(xiàn)下載文件的兩種方法。分享下,有用到的朋友看看哦。

方法一:

<?php/*** 下載文件* header函數(shù)**/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函數(shù)的用法。

方法二:

<?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技術(shù)php 下載保存文件保存到本地的兩種實(shí)現(xiàn)方法,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 静宁县| 金阳县| 余庆县| 安阳市| 达州市| 莎车县| 淮滨县| 大城县| 慈利县| 锦屏县| 鄂伦春自治旗| 京山县| 韩城市| 大城县| 手游| 道真| 肇源县| 敦化市| 余江县| 桐城市| 余江县| 和林格尔县| 海口市| 绍兴县| 石泉县| 东平县| 沙田区| 西华县| 富源县| 迁西县| 马鞍山市| 达州市| 平昌县| 麦盖提县| 长丰县| 六安市| 浮山县| 涞水县| 稷山县| 潞城市| 河西区|