Home > Backend Development > PHP Tutorial > php实现文件上载

php实现文件上载

WBOY
Release: 2016-06-13 13:02:45
Original
972 people have browsed it

php实现文件下载

以前一直写java程序,最近根据项目需要,学习了一下php编程,刚起步学的还不多,现在在此向新手们分享一下我写文件下载的一点经验。

?

实现文件下载很简单,就只需要一个页面downLoad.php

====================================================================

?

$filePath = "FileList/";//此处给出你下载的文件在服务器的什么地方

$fileName = "test.rar";

?

//此处给出你下载的文件名

$file = fopen($filePath . $fileName, "r"); // ? 打开文件

//输入文件标签

Header("Content-type:application/octet-stream ");

Header("Accept-Ranges:bytes ");

Header("Accept-Length: ? " . filesize($filePath . $fileName));

Header("Content-Disposition: ? attachment; ? filename= " . $fileName);

// ? 输出文件内容

echo fread($file, filesize($filePath . $fileName));

fclose($file);

exit;

?>

======================================================================

就这么短短几句代码就能实现文件下载了,简单吧,呵呵


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template