Php 强制下载不同的文件
我正在尝试强制下载php。从这里开始: . 单击sterling图像&下一页提供了三种格式的选项 这是我的php代码Php 强制下载不同的文件,php,Php,我正在尝试强制下载php。从这里开始: . 单击sterling图像&下一页提供了三种格式的选项 这是我的php代码 <?php header('Content-disposition: attachment; filename=sterling02md.jpg'); header('Content-type: image.jpg'); readfile('sterling02md.jpg'); header('Content-disposition: attachment; filen
<?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。如何修复代码,以便用户可以下载所选文件?
谢谢在查询字符串
download.php?option=1中设置选项
if (!isset($_REQUEST['option']) {
//redirect away
}
if ($_REQUEST['option'] == 1) {
header(...)
//sterling02md.jpg
}
您的内容类型不正确。您必须提供文件的mime类型,即
image/jpeg
。不是image.jpg
同样,您不能在一个HTTP请求中强制下载3个单独的文件。虽然某些浏览器确实支持多个文件,但必须将每个文件封装在单独的MIME正文块中,而您并没有这样做
提供这3个文件的.zip压缩副本供一次下载,或者提供3个单独的下载链接,每个链接一个文件。您可以尝试一些类似的方法,例如在图像
downalod.php?img=sterling02
$image = isset($_GET['img']) ? $_GET['img'] : "noimage" ;
$image .= ".jpg";
header('Content-disposition: attachment; filename='.$image);
header('Content-Type: image/jpeg');
readfile($image);
但是如果你想强制下载,那么使用
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Transfer-Encoding: binary ");
header('Content-disposition: attachment; filename='.$image);
readfile($image);
你好,马克,谢谢你的回复。您可能会猜到,我对php一无所知。我从网上得到了上面的密码。如何“将每一个都封装在单独的MIME体块中”?这样做不值得费心。并不是所有的浏览器都支持它。谢谢大家。我会去尝试并报告。我甚至不确定我有一个查询字符串。就像我说的,我对php一无所知。坦率地说,这让我很恼火。