title: PHP createThumbnail function troubleshooting
body: <p>I'm using this function, to create thumbnails of images uploaded by the user, that I found here: <a href="http://webcheatsheet.com/php/create_thumbnail_images.php" rel="nofollow">http://webcheatsheet.com/php/create_thumbnail_images.php</a> :</p>
  
  <pre><code>function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
  {
    // open the directory
    $dir = opendir( $pathToImages );
  
  // loop through it, looking for any/all JPG files:
  if (false !== ($fname = readdir( $dir ))) {
      // parse path for the extension
      $info = pathinfo($pathToImages . $fname);
  
  // continue only if this is a JPEG image
  if ( strtolower($info['extension']) == 'jpg' )
  {
    echo "Creating thumbnail for {$fname} &lt;br /&gt;";
  
    // load image and get image size
    $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
    $width = imagesx( $img );
    $height = imagesy( $img );
  
    // calculate thumbnail size
    $new_width = $thumbWidth;
    $new_height = floor( $height * ( $thumbWidth / $width ) );
  
    // create a new temporary image
    $tmp_img = imagecreatetruecolor( $new_width, $new_height );
  
      // copy and resize old image into new image
  imagecopyresampled( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
  
    // save thumbnail into a file
    imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
  }
  }
  // close the directory
  closedir( $dir );
  }
  </code></pre>
  
  <p>This function works fine and does exactly what I want it to, but, despite this, I'm still getting errors from it. See errors below:</p>
  
  <p><code>Warning: opendir(images/008/01/0000288988r.jpg,images/008/01/0000288988r.jpg) [&lt;a href='function.opendir'&gt;function.opendir&lt;/a&gt;]: The directory name is invalid. (code: 267)</code></p>
  
  <p><code>Warning: opendir(images/008/01/0000288988r.jpg) [&lt;a href='function.opendir'&gt;function.opendir&lt;/a&gt;]: failed to open dir: No error</code></p>
  
  <p><code>Warning: readdir() expects parameter 1 to be resource, boolean given</code></p>
  
  <p>The problem, I think, is that I'm passing an actual file, not just a directory, into the parameters for the function. This is the case for <code>$pathtoimages</code> and <code>$pathtothumbs</code>. The function is supposed to search through the directory passed to it to find all images with the <code>.jpg</code> extension. But I would like to just perform the function on the one image uploaded at the time of upload. Is there someway to edit this function to allow for this?</p>
  
  <p>Thanks in advance </p>