PHP实现简单下载

栏目: PHP · 发布时间: 5年前

内容简介:PHP菜鸟

PHP菜鸟

PHP 文件为 download.php ,供下载的文件为 1.jpg .

<?php
    $filename="1.jpg";
    if(!file_exists($filename)){
        die("文件不存在");
    }                   //判断文件是否存在

    $fp =fopen($filename,"r");  //打开文件

    $file_size=filesize($filename);   //声明文件大小

    header("Content-type:application/octet-stream");
    header("Accept-Ranges:bytes");   //按字节大小返回
    header("Accept-Length:".$file_size);   //告诉浏览器文件大小
    header("Content-Disposition: attachment; filename=".$filename);  //下载框中文件的名字

    $buffer=1024;

    while(!feof($fp)){
        $data=fread($fp,$buffer);
    }            //判断文件是否下载完

    fclose($fp);    //关闭文件
?>

访问验证一下:

PHP实现简单下载 PHP实现简单下载

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Data Structures and Algorithm Analysis in Java

Data Structures and Algorithm Analysis in Java

Mark A. Weiss / Pearson / 2011-11-18 / GBP 129.99

Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course wa......一起来看看 《Data Structures and Algorithm Analysis in Java》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具