title: can't do imagejpeg() for multiple images
body: <p>I have this code and I need to make this work:</p>
  
  <pre><code>         if ($handle = opendir("images/")) { $i=0;
                     while (false !== ($file = readdir($handle))){
                      if ($file != "." &amp;&amp; $file != ".." &amp;&amp; $file != "Recursive Dir_Renfiles_dirname-filename.php") {
                          $filename[$i]=$file;
                          $i++;
                      }}}
                      //print_r($filename);
  
  foreach($filename as $filename){
      $percent = 0.5;
  
      // Content type
      header('Content-Type: image/jpeg');
  
      // Get new dimensions
      list($width, $height) = getimagesize($filename);
      $new_width = $width * $percent;
      $new_height = $height * $percent;
  
      // Resample    
      $image_p = imagecreatetruecolor($new_width, $new_height);
      $image = imagecreatefromjpeg($filename);
      imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  
      // Output
      imagejpeg($image_p, null, 100);    
  }
  </code></pre>
  
  <p>I there a way to make this work? Or is there another way to do this?</p>