PHP脚本下载文件无法在IE中运行 [英] PHP script to download file not working in IE

查看:154
本文介绍了PHP脚本下载文件无法在IE中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本从$ _GET ['key']获取一个键,查找数据库中的位置并使用readfile和一些标题来提供下载供使用。这适用于Firefox而不是IE8,无法在另一个IE上测试它。我在IE中收到以下错误:Internet Explorer无法从www.example.com下载download.php。好像它正在尝试下载PHP脚本。

I have a script that takes a key from $_GET['key'] , looks up the location in a database and uses the readfile together with some headers to present a download for the use. This works in Firefox but not IE8, haven't been able to test it on another IE. I get the following error in IE: "Internet Explorer cannot download download.php from www.example.com". As if it is trying to download the PHP script.


$the_query = "SELECT * FROM `files` WHERE `user_id`=" . $_SESSION['user_id'] . " AND `key`='" . $key . "'";

$result = mysql_query($the_query);
$row = mysql_fetch_array($result);

$file = '/var/www/vhosts/www.example.com/httpsdocs/uploads/' . $row['id'] . '/' . $row['file'];

header("Content-type: application/octet-stream");
header("Content-length: ".filesize($file));
header('Content-Description: File Transfer');
header("Cache-control: private");
header('Content-Disposition: attachment; filename=' . rawurlencode(basename($file)));
readfile($file);


推荐答案

解决错误:Internet Explorer无法下载下载来自www.example.com的.php,
将这些标题添加到您的脚本中:

To solve the error : "Internet Explorer cannot download download.php from www.example.com", Add these headers to your script:

header(Pragma:);

header(Cache-Control:);

代码将从标题中删除Cache-Control,这会导致下载问题。

The code will remove the Cache-Control from headers which makes the download problem.

以上代码应添加到顶部该文件。

The above code should be added at the top of the file.

它适用于我们。

这篇关于PHP脚本下载文件无法在IE中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆