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
qads
DevNet Resident
Posts: 1199 Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane
Post
by qads » Wed Jun 12, 2002 4:41 pm
ok i got my script working
Code: Select all
<?
if ($_FILESї'file'] != "") {
copy($_FILESї'file']ї'tmp_name'], "".$_FILESї'file']ї'name'])
or die("Couldn't copy the file!");
} else {
die("No input file specified");
}
?>
that loads the file which is specified in a form on another page.
now how do i make sure that only .zip and .txt files are uploaded
thanks in adv
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Wed Jun 12, 2002 4:51 pm
try using..
i'm not sure about the wildcards im using, but it should work
Code: Select all
<?
if ($_FILESї'file'] != "") {
if ($_FILESї'file'] == "її:alnum:]]+.zip" || $_FILESї'file'] == "її:alnum:]]+.txt" ) {
copy($_FILESї'file']ї'tmp_name'], "".$_FILESї'file']ї'name'])
or die("Couldn't copy the file!");
} else{
echo "make sure it's zip or txt";
}
} else {
die("No input file specified");
}
?>
qads
DevNet Resident
Posts: 1199 Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane
Post
by qads » Wed Jun 12, 2002 5:47 pm
nope that does't work, it stops the upload of any kind.
Jim
Forum Contributor
Posts: 238 Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas
Post
by Jim » Wed Jun 12, 2002 5:53 pm
Use ereg() to validate it against the uploaded file thusly:
Code: Select all
if (!ereg('(.jpg|.gif)$', $userfile)) {
echo 'File is not a valid .gif or .jpg image!';
}
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Jun 12, 2002 7:06 pm
you may also check against the mime-type
Code: Select all
$accepted = array('application/x-zip-compressed', 'text/plain', ...);
if (in_array($_FILESї'file']ї'type'], $accepted)
...