我一直试图用PHP解压缩一个文件几天而没有成功。
我有以下功能:
function zipFileErrMsg($errno) {
// using constant name as a string to make this function PHP4 compatible
$zipFileFunctionsErrors = array(
//ZIP_ER_OK 0 /* N No error */
'ZIPARCHIVE::ER_MULTIDISK' => 'Multi-disk zip archives not supported.',
'ZIPARCHIVE::ER_RENAME' => 'Renaming temporary file failed.',
'ZIPARCHIVE::ER_CLOSE' => 'Closing zip archive failed',
'ZIPARCHIVE::ER_SEEK' => 'Seek error',
'ZIPARCHIVE::ER_READ' => 'Read error',
'ZIPARCHIVE::ER_WRITE' => 'Write error',
'ZIPARCHIVE::ER_CRC' => 'CRC error',
'ZIPARCHIVE::ER_ZIPCLOSED' => 'Containing zip archive was closed',
'ZIPARCHIVE::ER_NOENT' => 'No such file.',
'ZIPARCHIVE::ER_EXISTS' => 'File already exists',
'ZIPARCHIVE::ER_OPEN' => 'Can\'t open file',
'ZIPARCHIVE::ER_TMPOPEN' => 'Failure to create temporary file.',
'ZIPARCHIVE::ER_ZLIB' => 'Zlib error',
'ZIPARCHIVE::ER_MEMORY' => 'Memory allocation failure',
'ZIPARCHIVE::ER_CHANGED' => 'Entry has been changed',
'ZIPARCHIVE::ER_COMPNOTSUPP' => 'Compression method not supported.',
'ZIPARCHIVE::ER_EOF' => 'Premature EOF',
'ZIPARCHIVE::ER_INVAL' => 'Invalid argument',
'ZIPARCHIVE::ER_NOZIP' => 'Not a zip archive',
'ZIPARCHIVE::ER_INTERNAL' => 'Internal error',
'ZIPARCHIVE::ER_INCONS' => 'Zip archive inconsistent',
'ZIPARCHIVE::ER_REMOVE' => 'Can\'t remove file',
'ZIPARCHIVE::ER_DELETED' => 'Entry has been deleted',
);
$errmsg = 'unknown';
foreach ($zipFileFunctionsErrors as $constName => $errorMessage) {
if (defined($constName) and constant($constName) === $errno) {
return 'Zip File Function error: '.$errorMessage;
}
}
return 'Zip File Function error: unknown<br />';
}
function unzip($file)
{
$zip = zip_open($file);
if(is_resource($zip)){
$tree = "";
while(($zip_entry = zip_read($zip)) !== false){
echo "Unpacking ".zip_entry_name($zip_entry)."\n";
if(strpos(zip_entry_name($zip_entry), DIRECTORY_SEPARATOR) !== false){
$last = strrpos(zip_entry_name($zip_entry), DIRECTORY_SEPARATOR);
$dir = substr(zip_entry_name($zip_entry), 0, $last);
$file = substr(zip_entry_name($zip_entry), strrpos(zip_entry_name($zip_entry), DIRECTORY_SEPARATOR)+1);
if(!is_dir($dir)){
@mkdir($dir, 0755, true) or die("Unable to create $dir<br />");
}
if(strlen(trim($file)) > 0){
$return = @file_put_contents($dir."/".$file, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)));
if($return === false){
die("Unable to write file $dir/$file<br />");
}
}
}else{
file_put_contents($file, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)));
}
}
}else{
echo "Unable to open zip file - ". $zip ." - ". zipFileErrMsg($zip)."<br />";
}
}
然后打电话: 解压缩( 'AutoHoje.zip');
输出为:无法打开zip文件 - 5 - Zip文件功能错误:读取错误
我已将文件CHMOD到777但仍然没有。 zip文件由具有有限访问权限的FP用户上传 - 仅读取和写入。 我有一个具有更多权限的不同FTP用户。但是脚本是由webuser运行的,对吗?
我测试了在我的电脑上解压缩文件,没有问题。 任何人都可以解释一下吗?
由于