Page 1 of 1
upload file question
Posted: Mon Nov 15, 2004 9:51 pm
by ecaandrew
how would i take this code and make it so it only accepts JPEG/GIF files ONLY
thanks...
Code: Select all
if($_FILES['thumb']['size'] > 0)
{
$temp1 = explode(".", $_FILES['thumb']['name']);
$thumb = $ident . "." . $temp1[(count($temp1) - 1)];
copy($_FILES['thumb']['tmp_name'], $thumb_dir . $thumb)
or die ("Could not copy " . $thumb_dir . $thumb);
$thumb_url .= $thumb;
}
else
{
$thumb_url = "";
}
thanks
Posted: Tue Nov 16, 2004 2:31 am
by kettle_drum
Just add:
And see for a moment what the output is, and then i hope you can figure out what to do.
Posted: Tue Nov 16, 2004 2:40 am
by phpScott
hint: check the type and compare it to what you want.

Posted: Tue Nov 16, 2004 6:42 am
by John Cartwright
everyone throw in a bit hint until he can get it
hint: it will require an IF
Posted: Tue Nov 16, 2004 1:09 pm
by ecaandrew
Code: Select all
if ( $_FILES['thumb']['type'] == "application/zip" ) {
if($_FILES['thumb']['size'] > 0) {
$temp1 = explode(".", $_FILES['thumb']['name']);
$thumb = $ident . "." . $temp1[(count($temp1) - 1)];
copy($_FILES['thumb']['tmp_name'], $thumb_dir . $thumb)
or die ("Could not copy " . $thumb_dir . $thumb);
$thumb_url .= $thumb;
} else {
$thumb_url = "";
}
} else {
print "this file has to be a zip file.";
}
Posted: Tue Nov 16, 2004 2:32 pm
by kettle_drum
bingo!

Posted: Tue Nov 16, 2004 4:17 pm
by ecaandrew
thx now to do multiple file types, do i have to do two IF's or can i put like
and OR statement?
Posted: Tue Nov 16, 2004 9:19 pm
by kettle_drum
You can use multiple if's or you can make an array of file types and use in_array() to see if its in the array.