All pastes #265391 Raw Edit

gilesw

public php v1 · immutable
·published 2006-12-03 07:08 UTC
rendered paste body
<?php$target = "../upload/";$target = $target . basename( $_FILES['uploaded']['name']) ;//php file upload errors$error_codes = array(        0=>"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 filetry{//inbuilt php file upload  errorsif  ($_FILES['uploaded']['error']){        throw new Exception($error_codes[$_FILES['uploaded']['error']]);}//This is our size conditionif ($_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 exitcatch (Exception $e) {        echo $e->getMessage();        exit();}//////////////////////////////////////////////start movingtry{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 onecatch (Exception $e) {    echo $e->getMessage();}?>