"There is no error, the file uploaded with success", 1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini", 2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 3=>"The uploaded file was only partially uploaded", 4=>"No file was uploaded", 6=>"Missing a temporary folder", 7=>"Failed to write file to disk", 8=>"File upload stopped by extension" ); //////////////////////////////////////////////start tests of temporary file try{ //inbuilt php file upload errors if ($_FILES['uploaded']['error']){ throw new Exception($error_codes[$_FILES['uploaded']['error']]); } //This is our size condition if ($_FILES['uploaded']['size'] > 350000){ throw new Exception("Your file is too large"); } //check if upload is an image (exif returns positive integer if it is) if(!exif_imagetype($_FILES['uploaded']['tmp_name'])){ throw new Exception("Your file isn't an image."); } } // print an error if there is one and exit catch (Exception $e) { echo $e->getMessage(); exit(); } //////////////////////////////////////////////start moving try{ if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded"; }else{ throw new Exception("your file failed to upload"); } } // print an error if there is one catch (Exception $e) { echo $e->getMessage(); } ?>