title: how to download 2000+ images to zip when loading web page
body: <p>I have a webpage that logs on to facebook and displays a list of all friends with their picture.  I want to download all those pictures in order to a zip folder on my server for download.  Each picture has a unique id, but needs to be downloaded in order and renamed with the naming scheme 1.jpg, 2.jpg, etc.  </p>
  
  <p>I have tried a few things but nothing has worked.  First I tried:</p>
  
  <pre><code>$i = 1;
  foreach ($friends["data"] as $value) {
  $url = 'https://graph.facebook.com/' . $value["id"] . '/picture?type=large';
  copy($url,"$i.jpg");
  $i++;
  }
  </code></pre>
  
  <p>I thought this worked, but when I tried to open the images, they were all 0kb-also this does not save all the contents as a zip for easy download.</p>
  
  <p>I then tried this:</p>
  
  <pre><code>$i=1;
  foreach ($friends["data"] as $value) {
  $fileName = '&lt;img src="https://graph.facebook.com/' . $value["id"] . '/picture?type=large"/&gt; &lt;br /&gt;';
  echo $fileName;
  
  header("Content-Disposition: attachment; filename='".$fileName."'");
  $target=$fileName;
  $newName=$i.'jpg';
  rename($target, $newName);
  $i++;
  }
  </code></pre>
  
  <p>But this gave an error:</p>
  
  <pre><code>Warning: Cannot modify header information - headers already sent by (output started at /home/xxx/public_html/xxx.com/facebooksdk/facebook-php-sdk/examples/test.php:70) in /home/xxx0/public_html/xxx.com/facebooksdk/facebook-php-sdk/examples/test.php on line 138
  
  Warning: rename(graph.facebook.com/xx/picture?type=large"/&gt; &lt;br /&gt;,1jpg) [function.rename]: No such file or directory in /home/xxx/public_html/xxx.com/facebooksdk/facebook-php-sdk/examples/test.php on line 141
  </code></pre>
  
  <p>This second code I may not have even written correctly though...any help would be greatly appreciated!</p>