db 경로에서 파일의 Zip 폴더 생성 코드를 구현하고 PHP에서 압축 된 폴더를 다운로드했습니다. 나는 우분투 OS를 사용하고있다. Zip 파일이 PHP로 다운로드되지 않습니다.
public function actionDownload($id) {
$model = $this->loadModel($id, 'Document');
$results = array();
$results = $this->createZip($model);
$zip = $results[0];
$size = filesize($zip->filename);
if ($zip->filename) {
header("Content-Description: File Transfer");
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=\"" . $model->name . "\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $size);
ob_end_flush();
flush();
readfile($zip->filename);
// To Store User Transaction Data
//$this->saveTransaction();
//ignore_user_abort(true);
unlink($zip->filename);
$zip->close();
// Delete newly created files
foreach ($results[1] as $fl) {
unlink($fl);
}
}
}
public function createZip($model) {
$data = Document::model()->findAll('parent_folder=:id', array(':id' => (int) $model->document_id));
$fileArr = array();
foreach ($data as $type) {
$fileArr[] = $type->path;
}
$filestozip = $fileArr; // FILES ARRAY TO ZIP
$path = Yii::app()->basePath . DS . 'uploads' . DS . Yii::app()->user->id;
//$model->path = trim(DS . $path . DS); // DIR NAME TO MOVE THE ZIPPED FILES
$zip = new ZipArchive();
$files = $filestozip;
$zipName = "USR_" . Yii::app()->user->id . "_" . $model->name . "_" . date("Y-m-d") . ".zip";
$fizip = $path . DS . $zipName;
if ($zip->open($fizip, ZipArchive::CREATE) === TRUE) {
foreach ($files as $fl) {
if (file_exists($fl)) {
$zip->addFile($fl, basename($fl)) or die("<p class='warning'>ERROR: Could not add file: " . $fl . "</p>");
}
}
}
$resultArr = array();
$resultArr[] = $zip;
$resultArr[] = $files;
return $resultArr;
}
는 우편 번호 생성 코드가 잘 작동하고 생성 된 zip 파일이 있지만 문제는 파일의 소유자 것은
www가 데이터과 파일 권한은
읽기 전용입니다.
해당 압축 폴더에 대한 액세스 권한을 chmod($zip->filename, 0777)
으로 설정하려고하면 오류가 표시됩니까?
Error 500
chmod(): No such file or directory
실제로 파일이 있습니다.
그때 그것의
Error 500
filesize(): stat failed for /home/demo.user/myapp/public_html/backend/uploads/1/USR_1_kj_2013-12-23.zip
의 나에게 오류를 보여주는 다음의 zip 파일을 다운로드하지 chmod()
없이 노력하고합니다.
이것은 내가 직면하고있는 정말 이상한 문제입니다. 그것은 이유는 그 파일에 대한 어떤 작업을 수행 할 수없는 filesize()
하지만 어떤 이상한 일이 chmod()
또한 작동하지 않습니다 zip 파일의 일부 허가 문제가 될 것 같습니다.
도움이 필요합니다.
감사 www-data
권한을 읽을 경우
폴더에 이미 읽기/쓰기 권한이 있지만 PHP에서 해당 폴더에 zip 파일을 만들 때 읽기/쓰기 권한이 없음 – Sky
'$ zip-> close'를 추가 했습니까? 그것은 '사실'을 반환합니까? – hek2mgl
예 $ zip-> close()는 다운로드하기 전에 빈 페이지를 반환합니다. – Sky