Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $model = $this->findModel($id);
- $result = [];
- $file = tempnam(sys_get_temp_dir(), rand(0, 999999999).'zip');
- $zip = new \ZipArchive();
- if ($zip->open($file, \ZipArchive::CREATE) !== TRUE) {
- throw new \Exception('Cannot create a zip file');
- }
- foreach($model->productPhoto as $photo){
- $url = Yii::$app->params['urlStorage'].$photo->photo["folder"].'/'.$photo->photo["name"];
- $result[] = $url;
- $ReadFile = fopen ($url, "rb");
- if ($ReadFile) {
- $WriteFile = tmpfile();
- if ($WriteFile){
- while(!feof($ReadFile)) {
- fwrite($WriteFile, fread($ReadFile, 4096 ));
- stream_get_meta_data($WriteFile);
- $urlw = stream_get_meta_data($WriteFile)['uri'];
- }
- $zip->addFile($urlw);
- fclose($WriteFile);
- }
- fclose($ReadFile);
- }
- }
- $zip->close();
- $var = new Response();
- $var->sendFile($file, basename($file), ['mimeType'=>'application/zip']);
- $var->send();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement