richiejones24
-
Posts
55 -
Joined
-
Last visited
Posts posted by richiejones24
-
-
I am a total noob at php and am trying to write a upload script with validation the script uploads the files ok but the validation does not work any help or ideas would be much appreciated.
$allowed_filetypes = array('.jpg','.gif','.bmp','.png'); //These will be the types of file that will pass the validation.
$max_filesize = 1; // Maximum filesize in BYTES (currently 0.5MB).
$upload_path = '../pic_upload/'; // The place the files will be uploaded to.
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if(filesize($_FILES['pictures']['tmp_name'][$key]) > $max_filesize) // Now check the filesize, if it is too large then DIE and inform the user.
die('The file you attempted to upload is too large.');
$filename = $_FILES['pictures']['name'][$key];
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
if ($error == UPLOAD_ERR_OK) {
echo"$error_codes[$error]";
move_uploaded_file($_FILES["pictures"]["tmp_name"][$key],$upload_path . $_FILES["pictures"]["name"][$key]) or die("Problems with upload");
}
}
My First Upload Script with Validation
in PHP Coding Help
Posted
I do i just haven't included them on the post.