note 77697 deleted from features.file-upload by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: ash at atomic-network dot co dot uk 

----

I have always wanted to just allow image files; and found using an array which would work on IE, FF, And Opera etc.
would be to define the "image/name" for all of those.
as IE is "image/x-name" and FF is "image/name" etc.

<?php
function  image_valid($type)
{
	$file_types  = array(   
	'image/pjpeg' 	=> 'jpg', 
	'image/jpeg' 	=> 'jpg',
	'image/jpeg' 	=> 'jpeg',
	'image/gif' 	=> 'gif',
	'image/X-PNG'	=> 'png', 
	'image/PNG'	 	=> 'png', 
	'image/png' 	=> 'png', 
	'image/x-png' 	=> 'png', 
	'image/JPG' 	=> 'jpg',
	'image/GIF' 	=> 'gif',
	'image/bmp' 	=> 'bmp',
	'image/bmp' 	=> 'BMP',
	);
	
	if(!array_key_exists($type, $file_types))
	{
		return "FALSE";
	}
	else
	{
		return "TRUE";
	}
}

if(image_valid($_FILES['user_file']['type']) === "FALSE")
{
	die("Image file is not valid");
}
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.