3
하나의 zip 파일에 파일 배열을 쓰는 간단한 함수가 필요합니다. 온라인 자습서에서 일부 코드를 발견하고 약간 수정했지만 제대로 작동하지 않는 것 같습니다. 그것은 zip 파일을 생성하지만 나는 시도하고 그것을 추출 할 때 오류 얻을 :ZipArchive 파일이 유효하지 않습니다.
Windows cannot complete the extraction.
The Compressed (zipped) Folder '...' is invalid.
여기에 내가 함께 일하고 있어요 코드의를 :
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);
}
}
문 밖으로 다음 인쇄 디버그 :
For $valid_files - array of one file name (full path to file)
For $zip->numFiles - 1
For $zip->status - 0
The function returns true.
내가 뭘 잘못하고 있는지에 대한 아이디어가 있습니까?