php 下载和上传,PHP 文件的上传与下载

(一) 文件的下载

$file='drupalmo.srt';

if (file_exists($file)) {

header('Content-Description: File Transfer');

header('Content-Type: application/srt');

header('Content-Disposition: attachment; filename='.basename($file));

header('Content-Transfer-Encoding: binary');

header('Expires: 0');

header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

header('Pragma: public');

header('Content-Length: ' . filesize($file));

ob_clean();

flush();

readfile($file);

exit;

}

其中 Content-type可以为如下的格式,要注意:文件名和内容要保持关联,也就是如果内容是pdf,那么文件的扩展名也需要时pdf的,否则无法下载。application/pdf指用pdf程序打开。

case "pdf": $ctype="application/pdf"; break;

case "exe": $ctype="application/octet-stream"; break;

case "zip": $ctype="application/zip"; break;

case "doc": $ctype="application/msword"; break;

case "xls": $ctype="application/vnd.ms-excel"; break;

case "ppt": $ctype="application/vnd.ms-powerpoint"; break;

case "gif": $ctype="image/gif"; break;

case "png": $ctype="image/png"; break;

case "jpeg":

case "jpg": $ctype="image/jpg"; break;

default: $ctype="application/force-download";


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部