title: Extracting File Extension in PHP (image upload script)
body: <p>Can anyone tell me what is wrong with this? The file is renamed using a time stamp but the extension doesn't get extracted and placed in the new name.</p>
  
  <pre><code>    $filenameext = pathinfo($filename, PATHINFO_EXTENSION);
  
      $today = getdate();
      $uniqueStr = $today[year];
      $uniqueStr .= $today[mon];
      $uniqueStr .= $today[wday];
      $uniqueStr .= $today[mday];
      $uniqueStr .= $today[hours];
      $uniqueStr .= $today[minutes];
      $uniqueStr .= $today[seconds];
  
      $filename = $uniqueStr.".".$filenameext;
  </code></pre>
  
  <p>The full code:</p>
  
  <pre><code>&lt;?php
  $folder = 'images/';
  $orig_w = 500;
  
  if( isset($_POST['submit']) )
  {
      $imageFile = $_FILES['image']['tmp_name'];
      $filenameext = pathinfo($filename, PATHINFO_EXTENSION);
  
      $today = getdate();
      $uniqueStr = $today[year];
      $uniqueStr .= $today[mon];
      $uniqueStr .= $today[wday];
      $uniqueStr .= $today[mday];
      $uniqueStr .= $today[hours];
      $uniqueStr .= $today[minutes];
      $uniqueStr .= $today[seconds];
      $filename = $uniqueStr.".".$filenameext;
  
      list($width, $height) = getimagesize($imageFile);
  
      $src = imagecreatefromjpeg($imageFile);
      $orig_h = ($height/$width)* $orig_w;
  
      $tmp = imagecreatetruecolor($orig_w, $orig_h);
      imagecopyresampled($tmp, $src, 0,0,0,0,$orig_w,$orig_h,$width,$height);
      imagejpeg($tmp, $folder.$filename,100);
  
      imagedestroy($tmp);
      imagedestroy($src);
  
      $filename = urlencode($filename);
      header("Location: crop.php?filename=$filename&amp;height=$orig_h");
  }
  </code></pre>
  
  <p>?></p>