Re: Is it possible to test an uploaded file to check the type?

From: Date: Mon, 14 Jul 2003 02:21:02 +0000
Subject: Re: Is it possible to test an uploaded file to check the type?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-155036@lists.php.net to get a copy of this message
David Otton wrote:
$_FILES['userfile']['type'] The mime type of the file, if the browser provided this information. An example would be "image/gif".
     
So, check $_FILES['userfile']['type'] against a set of allowed file types, and you're set...
A client-supplied value isn't going to be too useful - it can be spoofed, or may not be present. (I believe a Windows browser would set the mime-type based purely on the file extension, though I haven't tested this myself).
Then my apologies. I thought php determined the file type on upload, and not rely on user input as your're saying. Makes me rethink some of my own code :)

« previous php.general (#155036) next »