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