【发布时间】:2012-11-20 16:32:59
【问题描述】:
我正在使用 ajax 调用来传递一个值。我已经这样做了,我想获取该值并在我的表上查找特定图像。
当我下载图像时,它不适合我。我查看了我的 php.ini 文件,我的 allow_furl_open 已关闭。我认为这可能是罪魁祸首。请忽略 mysql 位,因为我知道它应该更新,这不是我的代码,所以会被更改。
这里是代码。
if (isset($_POST['download'])) {
$sql = "SELECT `imageURL` FROM `digital_materials` WHERE `digital_materials`.`id` = '$id'";
$record = mysql_query($sql);
$row = mysql_fetch_assoc($record);
$fileName = $row['imageURL'];
$fileURL = 'images/products/' . $fileName;
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header('Content-Disposition: attachment; filename=' . $row['imageURL']);
readfile($fileURL);
exit();
}
这应该可以工作。有什么问题吗?
【问题讨论】:
-
'images/products/' . $fileName;不是网址所以应该没问题。 -
好的,谢谢您的信息。 :)
-
您是否尝试通过 ajax 响应返回来下载此文件? ajax 不适用于文件下载...
-
是的,这就是我目前正在尝试做的事情。
-
代码在我通过 ajax 请求调用的 php 文件中。
标签: php header content-type