【发布时间】:2014-10-23 23:27:12
【问题描述】:
我在发帖前检查了几个问题,包括:
在本地服务器上测试时,一切都按预期工作,但是当我们上传到实时站点时,下载的 zip 文件以 .cpgz 文件打开。
我们正在使用“Conferences”目录(即 Asset_Management)中的文件夹名称以 html 表单填充 SELECT 菜单(名为“Conference”)。
PHP 像这样连接成一个链接:
<a href="zip_folders.php?directtozip=' . $_POST["Conference"] . '">Download All As Zip</a>
我们的邮政编码设置了 zip 文件:
<?php
// WARNING
// This code should NOT be used as is. It is vulnerable to path traversal. https://www.owasp.org/index.php/Path_Traversal
// You should sanitize $_GET['directtozip']
// For tips to get started see https://stackoverflow.com/questions/4205141/preventing-directory-traversal-in-php-but-allowing-paths
//Get the directory to zip
$filename_no_ext= $_GET['directtozip'];
// we deliver a zip file
header("Content-Type: archive/zip");
// filename for the browser to save the zip file
header("Content-Disposition: attachment; filename=$filename_no_ext".".zip");
// get a tmp name for the .zip
$tmp_zip = tempnam ("tmp", "tempname") . ".zip";
//change directory so the zip file doesnt have a tree structure in it.
chdir('user_uploads/'.$_GET['directtozip']);
// zip the stuff (dir and all in there) into the tmp_zip file
exec('zip '.$tmp_zip.' *');
// calc the length of the zip. it is needed for the progress bar of the browser
$filesize = filesize($tmp_zip);
header("Content-Length: $filesize");
// deliver the zip file
$fp = fopen("$tmp_zip","r");
echo fpassthru($fp);
// clean up the tmp zip file
unlink($tmp_zip);
?>
但是当我解压文件时,它变成了.cpgz 文件。
为什么这可以在我们的本地服务器而不是我们的远程托管站点上运行?
编辑:我认为exec() 命令可能不可移植,但我不确定如何替换它。
【问题讨论】:
标签: php macos download directory zip