【问题标题】:Cannot extract .tgz file dowloaded from magento无法提取从 magento 下载的 .tgz 文件
【发布时间】:2015-06-12 09:02:02
【问题描述】:

我发现 magento 存在问题。我尝试通过将一个 .tgz 压缩文件与另一个 pdf 文件一起压缩来将其上传到 magento。但是,当我尝试从 magento 下载它时,.tgz 文件已损坏。我在 4-5 次不同的场合用不同的文件看到了这个因此我认为这是 Magento 的问题?但是,只需将 zip 文件解压缩到 PC 中,它就可以很好地工作。

请告诉我可能的原因和解决方案。

【问题讨论】:

  • “因此我认为它与但是有问题”?标点符号也会对读者有所帮助。
  • 检查该文件是否损坏,通过 FTP 进入该 magento 位置文件夹。
  • 仅供参考:Magento 2 有相反的问题:可下载产品:magento.stackexchange.com/questions/3528/…

标签: magento


【解决方案1】:

如何通过 FTP 下载该压缩文件。 您通过浏览器下载文件时可能出现中断

【讨论】:

  • 实际上我的客户会下载该文件,该文件将链接到magento中的可下载产品。所谓的 .tgz 文件附有特定的可下载产品
【解决方案2】:

您遇到的问题可能部分是由于 Magento 为压缩项目生成(可能不正确)HTTP-Headers 的方式。最终结果是项目可能会被损坏,因为它们可能会被双重压缩,但是,如果实际上这似乎是您遇到的问题,您可以做一些简单的事情。

  1. 不要使用SetOutputFilter DEFLATE
  2. 不要使用AddOutputFilterByType DEFLATE application/x-httpd-php
  3. 根据需要使用SetEnvIfNoCase 创建例外规则

所有这一切都是explained in more detail by Babs Gösgens,他还提供了一个 Magento .htaccess 模板,其中包含用于处理其中一些问题的定义:

<IfModule mod_deflate.c>

    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
    AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript application/x-javascript
    #AddOutputFilterByType DEFLATE application/x-httpd-php

    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.(?:pdf|doc)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.(?:avi|mov|mp3|mp4|rm)$ no-gzip dont-vary

</IfModule> 

【讨论】:

    【解决方案3】:

    这不是 magento 的问题。它的标题问题。另外你是如何下载文件的?你有直接下载链接吗?如果是,则将其删除并编写自定义操作以下载类似

    的内容
    public function downloadFileAction() {
            ignore_user_abort ( true );
            set_time_limit ( 0 ); // disable the time limit for this script
    
            $fullPath = Mage::getBaseDir () . "path_to_your_file/yourFile.tgz";
    
            if ($fd = fopen ( $fullPath, "r" )) {
                $fsize = filesize ( $fullPath );
                $path_parts = pathinfo ( $fullPath );
                $ext = strtolower ( $path_parts ["extension"] );
                switch ($ext) {
                    case 'tgz':
                        header('Content-Description: File Transfer');
                        header('Content-Type: application/octet-stream');
                        header('Content-Length: ' . $fsize);
                        header('Content-Disposition: attachment; filename=' . $path_parts ["basename"]);
                        readfile($fullPath);
                    default :
                        header ( "Content-type: application/octet-stream" );
                        header ( "Content-Disposition: filename=\"" . $path_parts ["basename"] . "\"" );
                        break;
                }
            }
        }
    

    并调用您的操作:

    $this->getUrl('your_controler') ?>index/downloadFile
    

    希望对你有帮助

    【讨论】: