相关疑难解决方法(0)

Rails上传到AWS创建.zip.cpgz文件循环

我遇到了一个奇怪的情况,一些文件,特别是ZIP格式,在我的Rails应用程序中上传到AWS时被破坏/转换.下载和解压缩后,它们会变成CPGZ格式,它会解压缩回ZIP,并无限制地执行此操作.

我没有注意到导致这种情况的模式,所以它看起来很零星,并且可以在上传之前确认文件没有损坏.我在此发现的唯一其他问题/主题与PHP有关,并且似乎是不同的情况.

我正在使用AWS SDK for Ruby v1(因为我的Rails版本而不是v2)和jQuery-File-Upload.由于某些文件很大,我使用的是分块上传.

在我的控制器中,预先设定的POST URL是这样创建的:

S3_BUCKET.presigned_post(key: "uploads/#{SecureRandom.uuid}-${filename}", success_action_status: '201')
Run Code Online (Sandbox Code Playgroud)

并且jQuery文件上传设置如此(为简洁起见,删除了一些部分):

this.$el.fileupload({
  fileInput: this.uploadField, // this is an <input type="file">
  url: this.awsURL, // https://BUCKET.s3.amazonaws.com/
  formData: JSON.parse(this.awsData), // {"AWSAccessKeyId":"...","key":"uploads/1234-${filename}","policy":"...","signature":"...","success_action_status":"201"}
  type: 'POST',
  autoUpload: true,
  paramName: 'file',
  dataType: 'XML',
  replaceFileInput: false,
  maxChunkSize: 1000000,
  add: function(event, data) {
    var file = data.files[0];
    var fileType = file.type;

    // Check file type
    if (~'ai sketch psd jpg jpeg png zip ttf woff eot gif'.indexOf(fileType.toLowerCase())) {
      return alert('Sorry, …
Run Code Online (Sandbox Code Playgroud)

zip ruby-on-rails amazon-s3 jquery-file-upload aws-sdk

14
推荐指数
1
解决办法
807
查看次数

使用PHP的压缩文件在提取后生成cpgz文件

我正在使用php压缩文件夹和文件,但是当我尝试打开zip文件时,我得到了一个cpgz文件.提取该文件后,我得到另一个zip文件.它的作用是低音扫描当前文件夹中的文件和文件夹以压缩.这是我使用的代码:

function Zip($source, $destination)
{
if (!extension_loaded('zip') || !file_exists($source)) {
    return false;
}

$zip = new ZipArchive();
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
    return false;
}

$source = str_replace('\\', '/', realpath($source));

if (is_dir($source) === true)
{
    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);

    foreach ($files as $file)
    {
        $file = str_replace('\\', '/', realpath($file));

        if (is_dir($file) === true)
        {
            $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
        }
        else if (is_file($file) === true)
        {
            $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
        }
    }
}
else if …
Run Code Online (Sandbox Code Playgroud)

php zip

5
推荐指数
1
解决办法
2790
查看次数

PHP下载脚本在Mac上创建不可读的ZIP文件

作为参考,我已经阅读并尝试了以下几个线程中的答案:

使用php创建和提供压缩文件

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

我的服务器上有一个zip文件.

  1. 当我使用Filezilla将Zip文件从我的服务器移动到我的Mac时,我可以正常打开它.

  2. 当我使用这个PHP代码将Zip文件下载到我的Linux机器时,它会正常打开.

  3. 当我使用这个PHP代码将Zip文件下载到我的Mac,使用Safari或Firefox时,我收到一条错误,说"解压缩失败"或"存档的结构已损坏"或我得到一个.cpgz文件 - 我相信意味着计算机正在压缩文件,而不是解压缩文件.

这是我用来提供zip文件的PHP代码.

$zipname = "myfile.zip";
$zippath = "/path/to/" . $zipname;

      if ($downloadzip = fopen ($zippath, "r")) {
            $fsize = filesize($zippath);

            header("Content-type: application/zip");
            header("Content-Disposition: attachment; filename=\"".$zipname."\"");
            header("Content-length: $fsize");
            header('Content-Transfer-Encoding: binary');
            #header("Cache-control: private"); //use this to open files directly

            echo fpassthru($downloadzip); // deliver the zip file

        }
        fclose ($downloadzip);
Run Code Online (Sandbox Code Playgroud)

我找到了一些有效的标题.我真的不知道或不关心它为什么工作,我很高兴它的工作原理...我尝试了很多不同的东西,.htaccess文件,php.ini/zlib设置.

这是答案 http://perishablepress.com/http-headers-file-downloads/

$zipName = 'myfile.zip';
$zipPath = 'mydirectory/' . $zipName;


    if (file_exists($zipPath)) {

        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: public");
        header("Content-Description: …
Run Code Online (Sandbox Code Playgroud)

php macos zip download

1
推荐指数
2
解决办法
4891
查看次数