Excluding non-JPEG images
Posted: Fri Aug 25, 2006 9:01 am
Hi,
I need a PHP script that excludes images sent from a form that aren't JPEGs. I originally tried this PHP script:
This script worked perfectly on most computers, but on those that hide file extensions it rejected even valid JPEG images. I tried the getimagesize() method below too as an alternative means of rejecting non JPEG files. It doesn't work either, can you help? Thanks – Leao
I need a PHP script that excludes images sent from a form that aren't JPEGs. I originally tried this PHP script:
Code: Select all
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']);
$ok=1;
if ($uploaded_type != 'image/jpeg') {
{
echo "Sorry your file needs to be a JPEG image.";
$ok=0;
}
if ($ok==0)
{
echo "Sorry your file was not uploaded";
}
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], 'images/title.jpg'))
{
echo "Your image has been uploaded.";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
?>Code: Select all
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']);
$ok=1;
list($ImportWidth,$ImportHeight,$ImageMimeType) = getimagesize($_FILES['uploaded']['tmp_name']) ;
if ($ImportMimeType != 'image/jpeg')
{
echo "Sorry your file needs to be a JPEG image.";
$ok=0;
}
if ($ok==0)
{
echo "Sorry your file was not uploaded";
}
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], 'images/title.jpg'))
{
echo "Your image has been uploaded.";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
?>