I'm changing some things around on my webapp and one of the major changes is assets are now stored in S3 (via filepicker.io) rather than locally. Here is some code I have to generate a zip file from an array of files

//example values
//loc could be uploads/1/7878837474test.jpg
//name coule be test.jpg

$downloadarray = array();
          while($row = mysql_fetch_array($res)){   
             $downloadarray[] =  array($row['loc'], $row['name']);
          $zipname = rand(0,9999) . 'download.zip';
          $zip = new ZipArchive;
          $zip->open($zipname, ZipArchive::CREATE);
          foreach ($downloadarray as $file) {
            $zip->addFile($file['0'], $file['1']);
          header('Content-Type: application/zip');
          header('Content-disposition: attachment; filename=' . $zipname);
          header('Content-Length: ' . filesize($zipname));

However now the $row['loc'] variable is going to be a remote URL. What is the best way to get external files set up? If possible I don't want to have to download the file onto the server. Just to let you know, if the adding seems to have been done in a strange way it is because originally uploads were stored in 5 different folders and I wanted to reset the file tree so they were all in the root of the zip. However this should no longer be necessary

4 Years
Discussion Span
Last Post by pixelsoul

If this is impossible could you tell me please as it's very frustrating!


Sure it's possible, but you will need to download the remote file first to your server before you can compress it.

A simple way to download a file

$url = 'http://fc09.deviantart.net/fs70/f/2010/158/d/c/Code_is_poetry_wallpaper_by_pixelsoul.png'; // url of file to download
$file = "downloads/download.jpg"; // download location and file name
$src = fopen($url, 'r');
$dest = fopen($file, 'w');

Of course you would need to do some changes here and there, randomize the file name, etc.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.