国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

利用php header函數實現文件下載保存到本地

2024-09-04 11:44:55
字體:
來源:轉載
供稿:網友

header() 函數向客戶端發送原始的 http 報頭,認識到一點很重要,即必須在任何實際的輸出被發送之前調用 header() 函數,在 php教程 4 以及更高的版本中,您可以使用輸出緩存來解決此問題,代碼如下:

  1. <html> 
  2. <?php 
  3. // 結果出錯 
  4. // 在調用 header() 之前已存在輸出 
  5. header('location: http://www.survivalescaperooms.com/'); 
  6. ?> 

語法:header(string,replace,http_response_code)

參數 描述 

string 必需,規定要發送的報頭字符串。 

replace 可選,指示該報頭是否替換之前的報頭,或添加第二個報頭。

默認是 true(替換),false(允許相同類型的多個報頭).

http_response_code 可選,把 http 響應代碼強制為指定的值,php 4 以及更高版本可用.

PHP實例代碼如下:

  1. <?php  
  2. function downfile() 
  3.  
  4.  $filename=realpath("resume.html"); 
  5.  header( "content-type:   application/octet-stream ");  
  6.  header( "accept-ranges:   bytes ");  
  7.     header( "accept-length: " .filesize($filename)); 
  8.  header( "content-disposition:   attachment;   filename= 4.html");  
  9.  echo file_get_contents($filename); 
  10.  readfile($filename);  
  11. downfile(); 
  12.  
  13. ?>  
  14. <?php 
  15.  
  16. function downfile($fileurl
  17. $filename=$fileurl
  18. $file   =   fopen($filename"rb");  
  19. header( "content-type:   application/octet-stream ");  
  20. header( "accept-ranges:   bytes ");  
  21. header( "content-disposition:   attachment;   filename= 4.doc"); 
  22.  
  23. $contents = ""
  24. while (!feof($file)) { 
  25.   $contents .= fread($file, 8192); 
  26. echo $contents
  27. fclose($file); 
  28.  
  29. $url=$_request['url']; 
  30. $url="http://www.survivalescaperooms.com"
  31. downfile($url); 
  32.  
  33. ?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高陵县| 罗源县| 金寨县| 江津市| 英德市| 宁强县| 吴旗县| 蓬莱市| 阳泉市| 福州市| 来安县| 衡东县| 米脂县| 秦皇岛市| 安平县| 石家庄市| 萨迦县| 三台县| 琼海市| 博白县| 沁阳市| 四子王旗| 康马县| 兰坪| 宽甸| 汉源县| 闻喜县| 南澳县| 阳曲县| 三都| 昌都县| 鲁山县| 绿春县| 安福县| 正蓝旗| 云林县| 平昌县| 东乡族自治县| 宜宾县| 武功县| 石家庄市|