我的代码能够打开我已经上传并移动到文件夹的zip文件的问题,zip文件上传很好,你可以在任何Zip程序中打开它然而,当我尝试用ZipArchive打开它来提取数据错误.
$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: ";
}
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,它向我显示错误代码19
ZIPARCHIVE :: ER_NOZIP - 19
这是我得到的错误,但文件存在,如果我使用zip_open,它返回它可以打开zip文件.
任何帮助都会非常棒
EDIT1 如果我上传我手动创建的zip文件(使用zip程序),那么上传工作正常.但是,如果我使用ZipArchive创建的zip文件,那么它会立即出错并出现错误19.
EDIT2 我现在添加了一个检查,以确保该文件存在于正确的目录中,并且还放置了该位置的打印,两者都匹配,但仍然是相同的问题.错误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();
}
Run Code Online (Sandbox Code Playgroud)
UPDATE1 所以我想我已经把它缩小到这个代码,或者我用来从系统下载.zip文件的下载脚本,如果我把zip保留在系统上并使用它完全相同的代码精细.
这是我的下载代码,也许我错过了导致问题的一些事情.
$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();
Run Code Online (Sandbox Code Playgroud)
这是 download.php 文件导致的问题,这里是解决方案。这是进行 OB CLEAN 而不是冲洗
///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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7832 次 |
| 最近记录: |