Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. $image = file_get_contents('http://url.com/image.jpg');
  2. file_put_contents('tmp/15.jpg', $image);
  3.  
  4. $image = file_get_contents('http://url.com/image.jpg');
  5. file_put_contents('tmp/16.jpg', $image);
  6.  
  7. $image = file_get_contents('http://url.com/image.jpg');
  8. file_put_contents('tmp/17.jpg', $image);
  9.  
  10.  
  11. $files = array(
  12.     'tmp/15.jpg',
  13.     'tmp/16.jpg',
  14.     'tmp/17.jpg'
  15. );
  16.  
  17. $valid_files = array();
  18. if(is_array($files)) {
  19.     foreach($files as $file) {
  20.         if(file_exists($file)) {
  21.             $valid_files[] = $file;
  22.         }
  23.     }
  24. }
  25.  
  26. if(count($valid_files > 0)){
  27.     $zip = new ZipArchive();
  28.     $zip_name = "images.zip";
  29.     if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){
  30.         $error .= "* Sorry ZIP creation failed at this time";
  31.     }
  32.      
  33.     foreach($valid_files as $file){
  34.         $zip->addFile($file);
  35.     }
  36.      
  37.     $zip->close();
  38.     if(file_exists($zip_name)){
  39.  
  40.         header("Pragma: public");
  41.         header("Expires: 0");
  42.         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  43.         header("Cache-Control: private",false);
  44.         header('Content-type: application/zip');
  45.         header('Content-Disposition: attachment; filename="'.$zip_name.'"');
  46.         readfile($zip_name);
  47.  
  48.         unlink($zip_name);
  49.     }
  50.  
  51. } else {
  52.     echo "No valid files to zip";
  53.     exit;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement