• php 下载保存文件保存到本地的两种方法


    第一种:

    1 <?php 2 function downfile()
    3 {
    4 $filename=realpath("resume.html"); //文件名
    5 $date=date("Ymd-H:i:m");
    6 Header( "Content-type: application/octet-stream ");
    7 Header( "Accept-Ranges: bytes ");
    8 Header( "Accept-Length: " .filesize($filename));
    9 header( "Content-Disposition: attachment; filename= {$date}.doc");
    10 echo file_get_contents($filename);
    11 readfile($filename);
    12 }
    13 downfile();
    14 ?>

    <?php
    //下载文件保存到本地
    //www.jbxue.com

    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);
    ?>

    第二种:

    1 <?php 2 //下载文件保存至本地
    3 //www.jbxue.com
    4 function downfile($fileurl)
    5 {
    6 $filename=$fileurl;
    7 $file = fopen($filename, "rb");
    8 Header( "Content-type: application/octet-stream ");
    9 Header( "Accept-Ranges: bytes ");
    10 Header( "Content-Disposition: attachment; filename= 4.doc");
    11 $contents = "";
    12 while (!feof($file)) {
    13 $contents .= fread($file, 8192);
    14 }
    15 echo $contents;
    16 fclose($file);
    17 }
    18 $url="url地址";
    19 downfile($url);
    20 ?>

  • 相关阅读:
    微信小程序动态更改样式
    ionic toggle点击返回true/false支持自定义
    ionic 页面传递参数
    ionic 搜索双向数据绑定失效
    关于select的默认样式问题
    nn
    MVC api json 格式
    iis 500 解决方法
    关于qquu8 的主页修改
    CentOS6.5下MAC
  • 原文地址:https://www.cnblogs.com/xlz307/p/3428231.html
Copyright © 2020-2023  润新知