<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. php語言

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

    時間:2025-02-16 08:26:01 php語言 我要投稿
    • 相關推薦

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

      PHP原始為Personal Home Page的縮寫,已經正式更名為 "PHP: Hypertext Preprocessor"。注意不是“Hypertext Preprocessor”的縮寫,這種將名稱放到定義中的寫法被稱作遞歸縮寫,以下是小編為大家搜索整理的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();

      ?>

      或

      ?

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

      方法一:

      ?

      /**

      * 下載文件

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

      ?>


    更多相關文章推薦:

    1.在PHP中使用RSS技術的方法

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

    3.解決PHP的failed opening required問題的方法

    4.PHP頁面漏洞分析的方法

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

    6.php采用ajax數據提交post與post常見方法總結

    7.攻擊方法注射語句構造php+mysql

    8.有關phpmailer的.詳細介紹及使用方法

    9.PHP插入數據庫的方法

    10.Python中子類怎樣調用父類方法

    【PHP下載保存文件保存到本地的方法】相關文章:

    php實現簡單文件下載的方法07-24

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

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

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

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

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

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

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

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

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人