简体   繁体   English

使用Wordpress的PHP文件下载可在localhost上运行,但不能在实时服务器上运行

[英]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.

相关问题 PHP - file_get_contents() 在 localhost 但在实时服务器上完美运行 - PHP - file_get_contents() works perfectly on localhost but on live server PHP套接字服务器在本地主机上工作,但在实时服务器上不工作 - php socket server works on localhost but not on live server php: @fopen 在 localhost 中工作,但在实时服务器中无效 - php: @fopen works in localhost but not in live server PHP强制下载可在localhost上运行,但不能在托管服务器上运行 - PHP force download works on localhost but not on hosting server 将 PDF 上传到 WordPress 可以在本地主机上工作,但不能在具有强大插件的实时服务器上工作 - Uploading PDFs to WordPress works in localhost but not on a live server with Formidable plugin php套接字服务器仅在localhost上有效,而在实时服务器上不可用 - php socket server works only on localhost but not live server PHP Cookies 在本地主机上运行良好,但在实时服务器上不起作用 - PHP Cookies works well on localhost, but it's not working on live server php 代码在 xampp 本地主机上运行良好,但在实时服务器上运行不正常 - php code works fine on xampp localhost but not working on live server 路由在localhost上有效,但在实时服务器上无效 - Routing works on localhost, but not on live server phpmailer可在localhost上运行,但不能在实时服务器上运行 - phpmailer works on localhost but not on live server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM