解压缩后,PHP压缩目录成为cpgz文件 [英] PHP zipped directory becomes cpgz file when extracted

查看:128
本文介绍了解压缩后,PHP压缩目录成为cpgz文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发布之前,我已经检查了一些问题,包括以下内容:

I've checked a few questions before posting, including the following:

PHP下载脚本在以下位置创建了不可读的ZIP文件Mac

打开下载的zip文件会创建cpgz文件吗?

在本地服务器上进行测试时,所有操作均按预期进行,但是当我们将下载的zip文件上传到实时站点时,将其作为.cpgz文件打开.

While testing on a local server everything worked as intended, however when we uploaded to the live site the downloaded zip files opened as .cpgz files.

我们正在以html格式填充SELECT菜单(名为"会议"),其文件夹名称位于"Conferences"目录(即Asset_Management)中.

We're populating a SELECT menu (named "Conference") in an html form with the folder names in our "Conferences" directory (i.e. Asset_Management).

PHP串联成这样的链接:

The PHP concatenates into a link as such:

<a href="zip_folders.php?directtozip=' . $_POST["Conference"] . '">Download All As Zip</a>

我们的邮政编码设置了zip文件:

Our zipping code sets up the zip file:

<?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文件.

But when I unzip the file it becomes a .cpgz file.

为什么这可以在我们的本地服务器而不是我们的远程托管站点上工作?

我认为exec()命令可能不是可移植的,但是我不确定如何替换它.

I think the exec() command might not be portable, but I'm not sure how to replace that.

推荐答案

我们的服务器禁用了execfpassthru命令,因此实际上没有任何内容写入zip文件中.解压缩一个空的zip文件后,我得到了.cpgz文件.

Our server had the exec and fpassthru commands disabled, so nothing was actually being written into the zip files. Unzipping an empty zip file gave me the .cpgz file.

这篇关于解压缩后,PHP压缩目录成为cpgz文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆