3
ファイルの配列を1つのzipファイルに書き込むシンプルな関数が必要です。私はオンラインチュートリアルからいくつかのコードを見つけてわずかに修正しましたが、うまく動作しないようです。これは、zipファイルを作成しますが、私は試してみて、それを抽出したとき、私はエラーを取得する:デバッグ文は次のようにプリントアウトされZipArchiveファイルが無効です
public function create_zip($files = array(),$destination = '',$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return 'file exists'; }
$valid_files = array();
if(is_array($files)) {
//cycle through each file
foreach($files as $file) {
//make sure the file exists
if(file_exists($file)) {
$valid_files[] = $file;
}
}
}
Zend_Debug::dump($valid_files);
if(count($valid_files)) {
//create the archive
$zip = new ZipArchive();
if($zip->open($destination, ZIPARCHIVE::CREATE) !== true) {
return 'could not open zip: '.$destination;
}
//add the files
foreach($valid_files as $file) {
$zip->addFile($file);
}
//debug
Zend_Debug::dump($zip->numFiles);
Zend_Debug::dump($zip->status);
$zip->close();
//check to make sure the file exists
return file_exists($destination);
} else {
return 'no valid failes'. count($valid_files);
}
}
:
Windows cannot complete the extraction.
The Compressed (zipped) Folder '...' is invalid.
ここで私が働いているコードです。
For $valid_files - array of one file name (full path to file)
For $zip->numFiles - 1
For $zip->status - 0
The function returns true.
私が間違っていることについてのアイデアはありますか?