一级日韩免费大片,亚洲一区二区三区高清,性欧美乱妇高清come,久久婷婷国产麻豆91天堂,亚洲av无码a片在线观看

php語(yǔ)言

PHP下載保存文件保存到本地的方法

時(shí)間:2025-02-16 08:26:01 php語(yǔ)言 我要投稿
  • 相關(guān)推薦

PHP下載保存文件保存到本地的方法

  PHP原始為Personal Home Page的縮寫(xiě),已經(jīng)正式更名為 "PHP: Hypertext Preprocessor"。注意不是“Hypertext Preprocessor”的縮寫(xiě),這種將名稱(chēng)放到定義中的寫(xiě)法被稱(chēng)作遞歸縮寫(xiě),以下是小編為大家搜索整理的PHP下載保存文件保存到本地的方法,歡迎大家閱讀!更多精彩內容請及時(shí)關(guān)注我們應屆畢業(yè)生考試網(wǎng)!

  第一種:

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

  方法一:

  ?

  /**

  * 下載文件

  * 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函數的用法。

  方法二:

  ?

  //文件下載

  //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();

  ?>


更多相關(guān)文章推薦:

1.在PHP中使用RSS技術(shù)的方法

2.php生成縮略圖的兩種方法

3.解決PHP的failed opening required問(wèn)題的方法

4.PHP頁(yè)面漏洞分析的方法

5.判斷數組是否為空的五大方法

6.php采用ajax數據提交post與post常見(jiàn)方法總結

7.攻擊方法注射語(yǔ)句構造php+mysql

8.有關(guān)phpmailer的.詳細介紹及使用方法

9.PHP插入數據庫的方法

10.Python中子類(lèi)怎樣調用父類(lèi)方法

【PHP下載保存文件保存到本地的方法】相關(guān)文章:

php實(shí)現簡(jiǎn)單文件下載的方法07-24

php實(shí)現編輯和保存文件的方法08-07

Java將對象保存到文件中再從文件中讀取對象的方法推薦09-05

php readfile下載大文件失敗的解決方法06-13

PHP從FTP服務(wù)器上下載文件的方法10-08

基于php下載文件的詳解10-26

php讀取文件內容的方法09-14

PHP讀取文件的正確方法09-02

PHP文件與目錄操作的方法11-16

一级日韩免费大片,亚洲一区二区三区高清,性欧美乱妇高清come,久久婷婷国产麻豆91天堂,亚洲av无码a片在线观看