簡體   English   中英

使用Wordpress的PHP文件下載可在localhost上運行,但不能在實時服務器上運行

[英]PHP file download with Wordpress works on localhost but not live server

我目前在強制我正在制作的Wordpress網站上進行文件下載時遇到一些問題。 在我的本地主機上,它可以正常工作,但是當我嘗試將其下載到實時服務器時,所有文件下載都中斷了。 例如,圖像不顯示,視頻和音頻文件不播放等。

這是我的代碼:

$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();

如果我在Chrome瀏覽器中檢查了響應,則在“預覽”和“響應”標簽中都會顯示“無法加載響應數據”。

有任何想法嗎? 任何幫助表示贊賞。

會將其添加為注釋,但不能。 它將使用ABSPATH給您帶來悲傷。 我會回顯您的$ download路徑,並確保它是正確的。 看這里-ABSPATH還是__FILE__?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM