1

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 />"; 
} 

}

次に呼び出します: unzip('AutoHoje.zip');

出力は次のとおりです: Unable to open zip file - 5 - Zip File Function error: Read error

ファイルを 777 に CHMOD しましたが、まだ何もありません。zip ファイルは、アクセスが制限された FP ユーザー (読み取りと書き込みのみ) によってアップロードされます。より多くの権限を持つ別の FTP ユーザーがいます。しかし、スクリプトは Web ユーザーによって実行されますよね?

PC でファイルの解凍をテストしましたが、問題はありませんでした。誰か光を当てることができますか?

ありがとう

4

0 に答える 0