

Just make sure that you're not checking the name of the file.DjDarkman wrote:I was thinking of a double file check first the form would check that if it`s *.png ,*.jpg or *.gif
Care to actually be bothered to explain it, though? >.>lost wrote:U can simply use gd library to check if uploaded file is image or not.
mm_freak wrote:Slackware users are dreamers. Sorry to say.


This looks good ,I want to use only php functions.Any other suggestions are welcome.bugalinux wrote:No no no, you just have to check the header mime content type of the uploaded file...
If you use PHP for your CMS you can use the 'mime_content_type' function.
mime_content_type($your_file) returns if $your_file is for example a Jpeg image : image/jpeg,
if it is a gif : image/gif, if it is a script : text/plain (a script is a text file), etc...
or the worst solution :
If your server is under Linux you can launch after the upload the system command 'file' to determine what type of file was uploaded (bad solution)...
Note : the system command 'file' and 'mime_content_type()' php function have the same mechanism, they find a file type by using a magic.mime file.
Good luck



//functions by x86anonymous
function IsImage($image){// IsImage($imgfile);
return getimagesize($image) ? true : false;
}
function IsValidImage($image){// IsValidImage($imgfile);
$img_types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG);
return in_array(exif_imagetype($image), $img_types);
//Note: You can add more valid types: http://pt.php.net/manual/en/function.exif-imagetype.php (Imagetype Constants)
}
function IsValidImage0($type){// IsValidImage0($imgfile_type);
$img_types = array('image/gif', 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png');
return in_array($type, $img_types);
}
/*
when you upload a file, is posted more information about the file:
>temporary filename (pointer): $imgfile
>original filename : $imgfile_name
>mime-type of uploaded file : $imgfile_type
*/
echo "IsImage($imgfile) = ";
echo IsImage($imgfile) ? "true<br />" : "false<br />"; // check if it is a image
echo "IsValidImage($imgfile) = ";
echo IsValidImage($imgfile) ? "true<br />" : "false<br />"; // check if it is a valid image type
echo "IsValidImage0($imgfile_type) = ";
echo IsValidImage0($imgfile_type) ? "true<br />" : "false<br />"; // check if it is a valid image type
Return to General Webmastering
Users browsing this forum: No registered users and 1 guest