简体   繁体   English

在php / magento中上传zip文件的问题

[英]Issues with zip file upload in php/magento

This is the code I am trying to upload a zip and extract zip at a location- 这是我试图在一个位置上传一个拉链和提取拉链的代码 -

//Path where extracted files to be stored, path is correct already checked
$path = Mage::getBaseDir(). DS .'pdf_locator'. DS;

$zip = new ZipArchive;
echo "<pre>";print_r($_FILES);
echo $_FILES['filename']['name'];

$name = $_FILES['filename']['name'];
$res = $zip->open("$name");//File name in server.
echo " --- ", $res, " --- ";
die;
if ($res === TRUE) {
    $zip->extractTo($path);//Destination directory
    $zip->close();
    echo 'successfully extracted';
} else {
    echo 'failed';
}

Output -- 输出 -

Array
(
    [filename] => Array
        (
            [name] => swap.zip
            [type] => application/zip
            [tmp_name] => /tmp/phpqx2qH2
            [error] => 0
            [size] => 478441
        )

)
swap.zip --- 11 --- 

I was expecting TRUE but it is throwing error code 11 [from the docs]. 我期待TRUE但它正在抛出错误代码11 [来自文档]。 Let me know what I am doing wrong with the code. 让我知道我在使用代码时遇到了什么问题。

FYI - Zip is enabled, please check screenshot. 仅供参考 - Zip已启用,请检查屏幕截图。

zipinfo

I think you should take the 'tmp_name' of the file located on the server to open the archive? 我认为您应该使用位于服务器上的文件的'tmp_name'来打开存档?

$name = $_FILES['filename']['name'];

Should look like this? 应该是这样的吗?

$name = $_FILES['filename']['tmp_name'];

If I am wrong: did you check the file system permissions (r/w/x)? 如果我错了:你检查了文件系统权限(r / w / x)吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM