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

  • 相关阅读:
    如何增加按钮的点击间隔时间
    如何增加button的点击范围
    定时器Timer的使用
    NSCache
    GCD和NSOperation的区别
    NSOperation实现线程间通信
    NSOperation添加操作依赖和监听
    自定义NSOperation
    NSOperation的多线程
    单例的实现(完整版代码)
  • 原文地址:https://www.cnblogs.com/xlz307/p/3428231.html
Copyright © 2011-2022 走看看