首頁  >  文章  >  後端開發  >  php上载文件

php上载文件

WBOY
WBOY原創
2016-06-13 11:02:51731瀏覽

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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn