Advertisement
abushyk

zip_photo_getter.php

Nov 13th, 2015
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.19 KB | None | 0 0
  1. if(intval($_SESSION['user_id'])>0 && preg_match('/^get_zip_photo\/(\d+)$/', $REQUESTURIPATH, $matches)){
  2.     $id=$matches[1];
  3.     $image_field='image'; //указываем системное имя поля с картинками в нашей модели
  4.     require_once(SITEBILL_DOCUMENT_ROOT.'/apps/system/lib/model/model.php');
  5.     $data_model = new Data_Model();
  6.     $form_data_shared = $data_model->get_kvartira_model(false, true);
  7.     $form_data_shared=$form_data_shared['data'];
  8.     $fields=array('id', $image_field, 'active');
  9.     foreach($form_data_shared as $k=>$v){
  10.         if(!in_array($k, $fields)){
  11.             unset($form_data_shared[$k]);
  12.         }
  13.     }
  14.            
  15.     $form_data_shared = $data_model->init_model_data_from_db ( 'data', 'id', $id, $form_data_shared, true );
  16.    
  17.     //Если такого объекта нет - отбрасываем     
  18.     if(!$form_data_shared){
  19.         exit();
  20.     }
  21.  
  22.     //Если объект неактивен - отбрасываем    
  23.     if($form_data_shared['active']['value']!=1){
  24.         exit();
  25.     }
  26.     $images=array();
  27.     if($form_data_shared[$image_field]['type']=='uploads' && is_array($form_data_shared[$image_field]['value']) && count($form_data_shared[$image_field]['value'])>0){
  28.         $images=$form_data_shared[$image_field]['value'];
  29.     }elseif($form_data_shared[$image_field]['type']=='uploadify_image' && is_array($form_data_shared[$image_field]['image_array']) && count($form_data_shared[$image_field]['image_array'])>0){
  30.         $images=$form_data_shared[$image_field]['image_array'];
  31.     }
  32.    
  33.     //Если картинок нет - отбрасываем        
  34.     if(empty($images)){
  35.         exit();
  36.     }
  37.            
  38.     $zip = new ZipArchive();
  39.     $zip_name = "photos_".$id.'_'.time().".zip";
  40.     $zip->open($zip_name, ZIPARCHIVE::CREATE);
  41.     foreach($images as $photo){
  42.         $zip->addFile(SITEBILL_DOCUMENT_ROOT.'/img/data/'.$photo['normal'], $photo['normal']);
  43.     }
  44.     $zip->close();
  45.     if(file_exists($zip_name)){
  46.         header("Pragma: public");
  47.         header("Expires: 0");
  48.         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  49.         header("Cache-Control: private", false);
  50.         header('Content-type: application/zip');
  51.         header('Content-Disposition: attachment; filename="'.$zip_name.'"');
  52.         readfile($zip_name);
  53.         unlink($zip_name);
  54.     }
  55.     exit();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement