我正在尝试强制下载 php。从这里:http://www.iwantanimage.com/animals/animals01.html http://www.iwantanimage.com/animals/animals01.html。单击英镑图像,下一页提供三种格式的选项。
这是我的 php 代码
<?php
header('Content-disposition: attachment; filename=sterling02md.jpg');
header('Content-type: image.jpg');
readfile('sterling02md.jpg');
header('Content-disposition: attachment; filename=sterling02lg.jpg');
header('Content-type: image.jpg');
readfile('sterling02lg.jpg');
header('Content-disposition: attachment; filename=sterling.jpg');
header('Content-type: image.jpg');
readfile('sterling02.jpg');
?>
然而,唯一下载的图像是 sterling02md.jpg。如何修复代码以便用户可以下载所选文件?
谢谢
您的内容类型不正确。您必须提供文件的 mime 类型,即image/jpeg
. not image.jpg
.
同样,您不能在单个 HTTP 请求中强制下载 3 个单独的文件。虽然某些浏览器确实支持多个文件,但您必须将每个文件封装在单独的 MIME 正文块中,但您并没有这样做。
要么提供这 3 个文件的 .zip 副本以供单次下载,要么提供 3 个单独的下载链接,每个链接一个文件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)