Home  >  Article  >  Backend Development  >  php上载文件

php上载文件

WBOY
WBOYOriginal
2016-06-13 11:02:51772browse

php下载文件
php下载文件遇到的两种方式
第一种
$file = 'data/upload/文件.exe';
@header("Location:$file");exit;
此种方式不可取。因为没有告诉浏览器下载的文件的类型,如果浏览器的mime类型中没有,那么就会打开这个链接。
第二种
$filename   =   './download/文件名.exe ';
$filesize   =   filesize($filename);
header( "Content-Type:   application/force-download ");
header( "Content-Disposition:   attachment;   filename= ".basename($filename));
header( "Content-Length:   ".$filesize);
$data   =   file_get_contents($filename);
echo   $data;
或者是readfile($filename);

Statement:
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