[英]Downloading a zip file to local drive with PHP and WordPress
我正在將WordPress用於網站,並希望包含一個菜單項,用於將zip文件從網站下載到本地驅動器。 我嘗試使用以下功能:
function download_binary_file($file) {
if (file_exists($file)) {
$base_name = basename($file);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$base_name.'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
}
但是執行此功能時,沒有顯示對話框來保存文件,而是在我的瀏覽器中顯示了zip文件的內容。 有任何想法嗎?
上載您的zip文件,然后創建菜單項,然后將htaccess重定向從菜單項添加到zip文件網址。 壓縮文件通常會自動下載。.我知道也有用於wordpress的下載管理器插件,使該過程非常容易。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.