File type

Hi all,

How I can get file type from a file path (ex. C:\folder\image.gif) when someone is trying to "Upload" an image on my server.

I need to make sure that the file is either (JPEG OR JPG OR GIF).

So can someone please provide me with any sample code that can help me verify the uploaded image type in PHP

I get the file path and save it in a var called $imagepath

Thanks in advance.
GiantMatrixAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sajuksCommented:
if(is_uploaded_file($_FILE['myFile']['tmp_name']))
  {
    list($width, $height, $type, $attr) = get_image_size($_FILES["file"]["tmp_name"])
    if ( $type == 'GIF' || $type == 'JPG' || $type == JPEG)
    {
        //image type valid do copy/move
    }
}


where myFile is <input type="file" name="myFile">

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ravenplCommented:
There is a special variable $_FILES['userfile']['type'] wich will read 'image/something...' while the uploaded file is an image.
Try it. Read more at http://pl.php.net/manual/en/features.file-upload.php
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.