File php文件强制下载错误
我正试图强制下载。这是我的密码:File php文件强制下载错误,file,File,我正试图强制下载。这是我的密码: <?PHP // Define the path to file $file = 'http://myimage.com/users/test/uploads/1234.png'; if(!file) { // File doesn't exist, output error die('file not found'); } else { header('Content-disposition: attach
<?PHP
// Define the path to file
$file = 'http://myimage.com/users/test/uploads/1234.png';
if(!file)
{
// File doesn't exist, output error
die('file not found');
}
else
{
header('Content-disposition: attachment; filename='.$file);
header('Content-type: application/octet-stream');
readfile($file);
}
?>
您的内容类型
错误。强制下载只需内容配置:附件
;将其更改为image/png
,而不是application/octet-stream
另外,您在打开之前有一个空格,请确保
标记外没有任何空行。好的。所以文件不存在!陛下真奇怪。。。变量$file destination可在浏览器中查看。。为什么它不能下载它?@droidus:文件在另一台服务器上吗?您的防火墙可能正在阻止它,或者远程fopen
可能被禁用。嗯,它正由其他人托管,是的。如何检查fopen是否被禁用?@droidus:进入php.ini
并将allow\u url\u fopen
更改为On
。如果它已经在
上,您可能需要取消阻止PHP.hm的端口80上的传出连接,但不确定它们是否允许我访问该端口。。。我必须和他们核实一下。。。在此期间我还能做些什么吗?