okay, a little background info:
I'm trying to validate the mime type of a file (I want only images) uploaded to a server running PHP 5.2.11 (no mime_content_type()
or finfo_open(FILEINFO_MIME_TYPE)
support), and I ran across this method of using the system() function to return the mime type:
PHP Code:
system("file -bi 'filename.jpg'");
and it works great. However, even when I assign it to a variable (e.g., $mimeType = system("file -bi 'filename.jpg'");
), the result is automatically output to the browser. So, if I write a script like so:
PHP Code:
$mimeType = system("file -bi 'filename.jpg'");
if(preg_match('/image/', $mimeType)){ echo 'filename.jpg is an image file'; }
else{ echo 'WARNING: filename.jpg is NOT an image file'; }
the browser displays:
Code:
image/jpegfilename.jpg is an image file
.
.
...Well, I guess that's more than "a little" background info.
But does anyone have an idea of how to hide the output from system() from being displayed?
Is there a better way to check the mime type (WITHOUT mime_content_type()
or finfo_open()
)?
thanks, everyone.
Bookmarks