[S] File type checking
Moderator: General Moderators
[S] File type checking
this is the problemo>
I use this syntax, not mine, so need help
field with name img1, method post
$_FILES['img1']['size']
can this be modified to check for file TYPE, need to check if the file is of JPG, JPEG or GIF
Thanks Ahead !
I use this syntax, not mine, so need help
field with name img1, method post
$_FILES['img1']['size']
can this be modified to check for file TYPE, need to check if the file is of JPG, JPEG or GIF
Thanks Ahead !
Last edited by Calimero on Tue Jul 27, 2004 2:05 am, edited 1 time in total.
...
Ok I looked at the MANUAL.
Is this the right way of thinking
JUST interested will the line
if ($size = getimagesize($filename))
return true - reccognise thet this is an image, or do I need some extra code to do this
I just drafted the code, sorry for syntax errors.
Is this the right way of thinking
Code: Select all
<?php
<?php
if ($size = getimagesize($filename))
{//upload file}
else
{//wont work}
?>
?>if ($size = getimagesize($filename))
return true - reccognise thet this is an image, or do I need some extra code to do this
I just drafted the code, sorry for syntax errors.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
basically
Code: Select all
if(($size = getimagesize($filename)) !== false)
{
switch($size[2])
{
case 1:
case 2:
// it's a GIF or JPEG file..
break;
default:
break;
}
}
else
{
die('upload unacceptable!');
}...
So to add PNG and BMP I do his correction:
NOTE> I havent touched this line>
switch($size[2])
Do I need to change it to
switch($size[4])
so my version functions.
Code: Select all
<?php
if(($size = getimagesize($filename)) !== false)
{
switch($size[2])
{
case 1:
case 2:
case 3:
case 6:
// it's a GIF or JPEG file.. and now PNG or BMP
break;
default:
break;
}
}
else
{
die('upload unacceptable!');
}
?>switch($size[2])
Do I need to change it to
switch($size[4])
so my version functions.