the
PHP Code:
else if (substr($img_name,0,-4) == "jpeg", $img_exts) && $img_size < $max_size)
{
move_uploaded_file($img_temp_loc,"/images" . $img_name);
}
should be
PHP Code:
else if (substr($img_name,0,-4) == "jpeg" && $img_size < $max_size)
{
move_uploaded_file($img_temp_loc,"/images" . $img_name);
}
and the full versions should be the below, I would have edited them in but I cant edit my posts.
none strlen
PHP Code:
<?php
$img_exts = array("jpg","jpeg","png","gif","tiff","bmp"); // list of allowed file types
$max_size = 40000; // max file size in bytes
$img_size = $_FILE["img"]["size"]; // returns the files size in bytes
$img_type = $_FILE["img"]["type"]; // returns the types as image/extenstions_here
$img_name = $_FILE["img"]["name"]; //returns the files name including extenstion
$img_temp_loc = $_FILE["img"]["tmp_name"]; // returns temp upload location of the image
$img_err = $_FILE["img"]["error"]
/* start the process of the validation */
if ($img_err > 0)
{
echo "There was an error uploading your image, please check to make sure the file is an image and try again.";
}
else
{
if (substr($img_name,0,-4) == "jpeg" && $img_size < $max_size)
{
move_uploaded_file($img_temp_loc,"/images" . $img_name);
}
else if (in_array(substr($img_name,0,-3), $img_exts) && $img_size < $max_size)
{
move_uploaded_file($img_temp_loc,"/images" . $img_name);
}
else
{
echo "either your image was to big or the file was not a valid image files please correct this and try again.";
}
}
?>
strlen version
PHP Code:
<?php
$img_exts = array("jpg","jpeg","png","gif","tiff","bmp"); // list of allowed file types
$max_size = 40000; // max file size in bytes
$img_size = $_FILE["img"]["size"]; // returns the files size in bytes
$img_type = $_FILE["img"]["type"]; // returns the types as image/extenstions_here
$img_name = $_FILE["img"]["name"]; //returns the files name including extenstion
$img_temp_loc = $_FILE["img"]["tmp_name"]; // returns temp upload location of the image
$img_err = $_FILE["img"]["error"]
/* start the process of the validation */
if ($img_err > 0)
{
echo "There was an error uploading your image, please check to make sure the file is an image and try again.";
}
else
{
if (substr($img_name,strlen($img_name) - 4,strlen($img_name)) == "jpeg" && $img_size < $max_size)
{
move_uploaded_file($img_temp_loc,"/images" . $img_name);
}
else if (in_array(substr($img_name,strlen($img_name) - 3,strlen($img_name)), $img_exts) && $img_size < $max_size)
{
move_uploaded_file($img_temp_loc,"/images" . $img_name);
}
else
{
echo "either your image was to big or the file was not a valid image files please correct this and try again.";
}
}
?>
I was doing some copy and pasting and forgot to remove the in_array() stuff from the jpeg search sorry about that. Now its done and save memory and processes if the file is a .jpeg instead of searching the arrays values first it does a simpler call to substr(). Ta-Da.