Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(intval($_SESSION['user_id'])>0 && preg_match('/^get_zip_photo\/(\d+)$/', $REQUESTURIPATH, $matches)){
- $id=$matches[1];
- $image_field='image'; //указываем системное имя поля с картинками в нашей модели
- require_once(SITEBILL_DOCUMENT_ROOT.'/apps/system/lib/model/model.php');
- $data_model = new Data_Model();
- $form_data_shared = $data_model->get_kvartira_model(false, true);
- $form_data_shared=$form_data_shared['data'];
- $fields=array('id', $image_field, 'active');
- foreach($form_data_shared as $k=>$v){
- if(!in_array($k, $fields)){
- unset($form_data_shared[$k]);
- }
- }
- $form_data_shared = $data_model->init_model_data_from_db ( 'data', 'id', $id, $form_data_shared, true );
- //Если такого объекта нет - отбрасываем
- if(!$form_data_shared){
- exit();
- }
- //Если объект неактивен - отбрасываем
- if($form_data_shared['active']['value']!=1){
- exit();
- }
- $images=array();
- if($form_data_shared[$image_field]['type']=='uploads' && is_array($form_data_shared[$image_field]['value']) && count($form_data_shared[$image_field]['value'])>0){
- $images=$form_data_shared[$image_field]['value'];
- }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){
- $images=$form_data_shared[$image_field]['image_array'];
- }
- //Если картинок нет - отбрасываем
- if(empty($images)){
- exit();
- }
- $zip = new ZipArchive();
- $zip_name = "photos_".$id.'_'.time().".zip";
- $zip->open($zip_name, ZIPARCHIVE::CREATE);
- foreach($images as $photo){
- $zip->addFile(SITEBILL_DOCUMENT_ROOT.'/img/data/'.$photo['normal'], $photo['normal']);
- }
- $zip->close();
- if(file_exists($zip_name)){
- header("Pragma: public");
- header("Expires: 0");
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
- header("Cache-Control: private", false);
- header('Content-type: application/zip');
- header('Content-Disposition: attachment; filename="'.$zip_name.'"');
- readfile($zip_name);
- unlink($zip_name);
- }
- exit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement