zoukankan      html  css  js  c++  java
  • 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);

    ?>

  • 相关阅读:
    jQuery 2.0.3 源码分析 回调对象
    JQuery+JQuery ui实现的弹出窗口+遮罩层+拖动+更改大小~!
    2019.8.25 小结
    2019.8.23 小结
    宜中食堂游记
    2019.8.21小结
    2019.8.22小结
    2019.8.19小结
    题解 CF499A 【Watching a movie】
    2019.8.18小结
  • 原文地址:https://www.cnblogs.com/ly312/p/2000225.html
Copyright © 2011-2022 走看看