[英]PHP file download with Wordpress works on localhost but not live server
I'm currently having some problems with forcing a file download on a Wordpress site I'm making. 我目前在强制我正在制作的Wordpress网站上进行文件下载时遇到一些问题。 On my localhost it works fine but when I try it to the live server all file downloads are broken.
在我的本地主机上,它可以正常工作,但是当我尝试将其下载到实时服务器时,所有文件下载都中断了。 For instance, images are not displaying, video and audio files don't play etc.
例如,图像不显示,视频和音频文件不播放等。
This is my code: 这是我的代码:
$title = $query[0]->post_title;
$mimetype = $query[0]->post_mime_type;
$guid = $query[0]->guid;
$filepath = str_replace(home_url().'/wp-content/uploads/', '', $guid);
$download = ABSPATH.'/wp-content/uploads/' . $filepath;
$filesize = filesize($download);
//Download file
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename='.$title);
header('Content-Type: '.$mimetype);
header('Content-Transfer-Encoding: '.$mimetype);
header('Content-Length: '.$filesize);
ob_clean();
flush();
readfile($download);
exit();
If I inspect the response in Chrome it says "Failed to load response data" both in the preview and response tab. 如果我在Chrome浏览器中检查了响应,则在“预览”和“响应”标签中都会显示“无法加载响应数据”。
Any ideas? 有任何想法吗? any help is appreciated.
任何帮助表示赞赏。
Would add this as a comment but can't. 会将其添加为注释,但不能。 It will be using ABSPATH that's giving you grief.
它将使用ABSPATH给您带来悲伤。 I'd echo out your $download path and make sure it is correct.
我会回显您的$ download路径,并确保它是正确的。 Look here - ABSPATH or __FILE__?
看这里-ABSPATH还是__FILE__?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.