ZipArchive无法打开文件-错误代码:19 [英] ZipArchive not opening file - Error Code: 19

查看:695
本文介绍了ZipArchive无法打开文件-错误代码:19的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码无法打开我已上传并移动到文件夹中的zip文件时出现问题,该zip文件可以很好地上传,但是当我尝试使用ZipArchive打开它时,您可以在任何Zip程序中打开它提取错误的数据.

Im having issues with my code being able to open a zip file that i have uploaded and moved into a folder, the zip file uploads fine and you can open it in any Zip program however, when i attempt to open it with ZipArchive to extract the data it errors.

    $path = "../"; // Upload directory      
    $count = 0;

    foreach ($_FILES['files']['name'] as $f => $name) {     
       if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path . $name))
             $count++; // Number of successfully uploaded file
    }

    $kioskFile = $_FILES['files']['name'][0];
    $kioskFile = explode(".", $kioskFile);
    $kioskFile = $kioskFile[0];
    $zipFile = "../" . $kioskFile . ".zip";     

    $zip = new ZipArchive;
    $res = $zip->open($zipFile);
    if ($res === true) {
        $zip->extractTo("./");
        $zip->close();
    } else {
        echo "Error Cannot Open Zip File - Error Code: ";
    }

当我运行代码时,它向我显示错误代码19

When i run the code it shows me a Error Code 19

ZIPARCHIVE :: ER_NOZIP-19

ZIPARCHIVE::ER_NOZIP - 19

这是我收到的错误消息,但是该文件存在,如果我使用zip_open,它将返回可以打开该zip文件的信息.

This is the error im getting, however the file exists and if i use zip_open, it returns that it can open the zip file.

任何帮助都将非常有用

EDIT1 如果我上传了我手动创建的zip文件(使用zip程序),则上传可以正常进行.但是,如果我使用ZipArchive创建的zip文件,则会立即出错并显示错误19.

EDIT1 If i upload a zip file that i manually create (using a zip program) then the upload works fine. However if i use a ZipArchive created zip file, then it instantly errors with a error 19.

EDIT2 现在,我添加了一个检查以确保该文件存在于正确的目录中,并且还打印了该位置,两者都匹配,但是仍然是相同的问题.错误19

EDIT2 I have now added a check to make sure the file exists in the right directory and also put a print of the location also, both match, however still the same issue. Error 19

    $path = "../"; // Upload directory      
    $count = 0;

    foreach ($_FILES['files']['name'] as $f => $name) {     
       if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path . $name))
             $count++; // Number of successfully uploaded file
    }

    $kioskFile = $_FILES['files']['name'][0];
    $kioskFile = explode(".", $kioskFile);
    $kioskFile = $kioskFile[0];
    $realpath = realpath("../");
    $zipFile = $realpath . "\\" .  $kioskFile . ".zip";     

    if (file_exists($zipFile)) {
        $extract = zip_extract($zipFile, "../");
        if ($extract === TRUE) {

        } else {
            echo "The file " . $zipFile . " cannot be opened";  
        }
    } else {
        echo "The file " . $zipFile . " does not exist";
        die();
    }

UPDATE1 因此,我想我将IVE的范围缩小到这部分代码,或者我用来从系统下载.zip文件的下载脚本,如果我将zip留在系统上并使用完全相同的代码,它就可以正常工作

UPDATE1 So i think ive narrowed it down to either this bit of code, or the download script that i use to download the .zip file from the system, if i leave the zip on the system and use the exact same bit of code it works fine.

这是我的下载代码,也许我错过了引起问题的内容.

Here is my download code, maybe ive missed something on this that is causing the issue.

    $fileID = $_GET['id'];
    $backupLoc = "backups/";
    $sql = "SELECT * FROM backups WHERE id = '" . addslashes($fileID) .  "' LIMIT 1";
    $res = mysql_query($sql);
    $row = mysql_fetch_array($res); 
    $backupFile = $row['backupFile'];
    $zipFile = $backupLoc . "/" . $backupFile . ".zip";
    $zipSize = filesize($zipFile);

    header('Content-type: application/zip');
    header('Content-Disposition: attachment; filename="' . basename($zipFile). '"'); 
    ob_end_flush();
    readfile($zipFile);
    exit;
    die();

推荐答案

是导致此问题的download.php文件,这是解决方案.这样做是为了进行OB CLEAN而不是Flush

It was the download.php file that was causing the issue, here is the solution. which was to do a OB CLEAN rather than a Flush

    ///echo "<div style='padding: 50px;'>Please Wait .....</div>";
    $fileID = $_GET['id'];
    $backupLoc = "backups/";
    $sql = "SELECT * FROM backups WHERE id = '" . addslashes($fileID) .  "' LIMIT 1";
    $res = mysql_query($sql);
    $row = mysql_fetch_array($res); 
    $backupFile = $row['backupFile'];
    $zipFile = $backupLoc . "/" . $backupFile . ".zip";
    $zipSize = filesize($zipFile);

    header('Content-type: application/zip');
    header('Content-Disposition: attachment; filename="' . basename($zipFile). '"'); 
    //ob_end_flush();
    ob_end_clean(); 
    readfile($zipFile);
    exit;
    die();

这篇关于ZipArchive无法打开文件-错误代码:19的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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