0

I use this way for download multiple files as zip :

$files = array('readme.txt', 'test.html', 'image.gif');
$zipname = 'file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
  $zip->addFile($file);
}
$zip->close();

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);

But the file file.zip be save on my host . I don't want to save on my host i just wanna download it withou save .

Thank

Amin
  • 5
  • 5
  • 2
    if you don't save it, then where are you going to download it from? you can run another script to clean it up with [unlink()](http://php.net/unlink) – mister martin May 20 '16 at 15:55
  • 1
    You may find [this useful](http://stackoverflow.com/questions/4357073/on-the-fly-zipping-streaming-of-large-files-in-php-or-otherwise/4357904#4357904) – Jonathan Yaniv Ben Avraham May 20 '16 at 16:03
  • @JonathanYanivBenAvraham Thank you but it can't help me – Amin May 20 '16 at 16:09
  • @mistermartin but if more than one user wanna to download a file at a momment make a promlem becouse many of my files have similar name – Amin May 20 '16 at 16:10
  • Firstly are you using any frameworks for this project? I.e Symfony2, Laravel, Zend, CakePHP, CodeIgniter? – Jonathan Yaniv Ben Avraham May 23 '16 at 08:16
  • Dear @JonathanYanivBenAvraham no i don't use – Amin May 23 '16 at 08:25
  • @Amin Okay, so I'm not entirely sure what you want this to do, do you want to create the file in your code and download it? like you would with xml or csv? Without saving it to the server? – Jonathan Yaniv Ben Avraham May 23 '16 at 08:27
  • @JonathanYanivBenAvraham I don't use XML or CSV .I just combination many files in one ZIP file and next send for user for download with class.httpdownload .But i wanna do it without save on my host because in future make many problem for me . – Amin May 23 '16 at 09:02
  • @Amin do you mean saving it on your server in a local directory, so it's only downloaded on the client computer? – Jonathan Yaniv Ben Avraham May 23 '16 at 09:04
  • @JonathanYanivBenAvraham Yes right . – Amin May 23 '16 at 09:20
  • You don't need to save it onto the server, just send it out in the headers. [link](http://stackoverflow.com/a/1754359/5971639) Where on your local directory is the file being saved? – Jonathan Yaniv Ben Avraham May 23 '16 at 09:29
  • If that doesn't help, try this: [Good Example](http://www.webinfopedia.com/multiple-file-download-by-creating-zip-file-in-PHP.html) – Jonathan Yaniv Ben Avraham May 23 '16 at 09:36
  • Thanks @JonathanYanivBenAvraham But in that two way you said the file after create save in host (like my script). In another word i am using thats ways. – Amin May 23 '16 at 13:24

0 Answers0