Hi, Im using this code to check an image file before upload. The test file definately has the mime type 'image/pjpeg' however the line
- Code: Select all
if ($type != "image/pjpeg")
always comes back true.
Any ideas why??
Thanks,
Nathan.
- Code: Select all
if (!is_uploaded_file($_FILES['userphoto']['tmp_name']))
{
$error = "you didn't select a file to upload.<br />";
}
else
{
if ($_FILES['userphoto']['size'] > $maxfilesize)
{
$error = "your image file was too large.<br />";
unlink($_FILES['userphoto']['tmp_name']);
}
else
{
$ext = strrchr($_FILES['userphoto']['name'], ".");
if ($ext != ".jpg" AND $ext != ".jpeg" AND $ext != ".JPG" AND $ext != ".JPEG" )
{
$error = "your file was an unacceptable type.<br />";
unlink($_FILES['userphoto']['tmp_name']);
}
else
{
$image = $_FILES['userphoto']['tmp_name'];
if (!getimagesize($image))
{
$error = "not a valid image - image size function failed.";
unlink($_FILES['userphoto']['tmp_name']);
}
else
{
$type = $_FILES['userphoto']['type'];
if ($type != "image/pjpeg")
{
$error = "not a valid image - MIME type rejected '$type'.";
unlink($_FILES['userphoto']['tmp_name']);
}
else
{
if ($_SESSION['photo'] != "noimage.jpg")
{
unlink("./images/userimages/".$_SESSION['photo']);
}
$newname = $_SESSION['user_name'].$ext;
move_uploaded_file($_FILES['userphoto']['tmp_name'],"./images/userimages/".$newname);
mysql_query("UPDATE techs SET photo='$newname' WHERE user_name='$user_name'") or die (mysql_error());
$_SESSION['photo'] = $newname;
}
}
}
}
}