Easy, secure image uploader for handling form submissions with PHP

This tool was developed by Michael Diamond (http://www.DigitalGemstones.com) 2007
and is released freely for personal and corporate use under the licence which can be found at: 
http://digitalgemstones.com/licence.php 
and can be summarized as: 
You are free to use this software for any purpose as long as Digital Gemstones is credited, 
and may redistribute the software in its original form or modified as you see fit,  
as long as any credit comments in the code remain unchanged. 

--------------------------------------------------------------------------------

The ImgUploader class is very self contained, all you really need to know for basic usage is as follows:

Constructor
  Pass to the constructor the information of one item in the $_FILES array - for instance, $_FILES['uploadedImage'] if your form used the name "uploadedImage".
  
upload_unscaled()
  upload_unscaled() takes two parameters, a directory (or series of directories) and a filename WITHOUT the extention.
    the directories should be from the web root (though you can of course use ../ to navigate above that).
    the filename will be appended with the appropriate extention automatically.

upload()
  upload() takes two additional parameters to upload_unscaled(), a maximum width and height for the image.
    The final image will be scaled down so it is no larger than either the width or height passed.
  there is an optional fifth parameter which defaults to false which ensure that images smaller than the maximum width and height are not scaled up
    Passing true to this parameter will scale up small images, though this may reduce quality
    
upload_unscaled() and upload() can be called as many times as needed, for instance to create a thumbnail in one directory, a medium image in another, and the full sized image (using upload_unscaled()) in an third directory.

--------------------------------------------------------------------------------

Maximum File Size
  This script will allow images up to 5MB.  To change that, simply modify the if statement on line 55.
    The script does not use the MAX_FILE_SIZE parameter of the html form since a malicious user can easily spoof that value.

Error Checking
  Both upload_unscaled() and upload() return false on failure, or the location of the image (from the web root) on success.
    Any failure, be it at upload time, not an image, or a nonexistant directory, will return false.
    Call getError() to return the associated error code and handle the error accordingly.
  Possible Errors and their codes:
    101 - File is too large
    102 - Upload failed or was interrupted
    103 - File was not uploaded
    104 - File is not an image
    105 - File is not an acceptable image (gif, jpeg, png)
    106 - File could not be saved because the directory does not exist

--------------------------------------------------------------------------------

Example Usage - see imguploader.test.php for a more complete example:
<?php
include 'ImgUploader.class.php';

$img = new imgUploader($_FILES['file']);
if($name = $img->upload('images/demoFile', '1000', 400,400))
  echo '<img src="'.$name.'" alt="aPicture" />';
  // will output as <img src="/images/demoFile/1000.jpg" alt="aPicture" /> assuming file is a jpg
else
  echo 'ERROR! '.$img->getError();
}
?>