PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ecaandrew
Forum Commoner
Posts: 72 Joined: Fri Nov 12, 2004 5:05 pm
Post
by ecaandrew » Mon Nov 15, 2004 9:51 pm
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
kettle_drum
DevNet Resident
Posts: 1150 Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England
Post
by kettle_drum » Tue Nov 16, 2004 2:31 am
Just add:
And see for a moment what the output is, and then i hope you can figure out what to do.
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Tue Nov 16, 2004 2:40 am
hint: check the type and compare it to what you want.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Tue Nov 16, 2004 6:42 am
everyone throw in a bit hint until he can get it
hint: it will require an IF
ecaandrew
Forum Commoner
Posts: 72 Joined: Fri Nov 12, 2004 5:05 pm
Post
by ecaandrew » Tue Nov 16, 2004 1:09 pm
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.";
}
kettle_drum
DevNet Resident
Posts: 1150 Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England
Post
by kettle_drum » Tue Nov 16, 2004 2:32 pm
bingo!
ecaandrew
Forum Commoner
Posts: 72 Joined: Fri Nov 12, 2004 5:05 pm
Post
by ecaandrew » Tue Nov 16, 2004 4:17 pm
thx now to do multiple file types, do i have to do two IF's or can i put like
and OR statement?
kettle_drum
DevNet Resident
Posts: 1150 Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England
Post
by kettle_drum » Tue Nov 16, 2004 9:19 pm
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.