php设置下载文件名

php设置下载文件名,第1张

写个新的控制器来让用户下载,而不是直接用过文件路径下载。 比如:

/index.php?controller=down_file&file=1.zip

然后在Controller里控制输出名就可以实现

$file = './路径/1.zip'

filename = '2.zip'

header('Content-Description: File Transfer')

header('Content-Type: application/octet-stream')

header("Content-type:text/htmlcharset=utf-8")

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

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

header('Expires: 0')

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

header('Pragma: public')

readfile($file)

exit

<?

//输出的类型

header('Content-type: application/octet-stream')

//输出文件的大小

header('Accept-Length: '.filesize('0.rar'))

//下载显示的名字

header('Content-Disposition: attachmentfilename="'.$_GET['id'].'.rar"')

//输出文件数据

print file_get_contents('0.rar')

?>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/12084771.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存