Page 1 of 1
$_FILES['uploadedfile']
Posted: Wed May 10, 2006 8:04 pm
by Jim_Bo
Hi,
$_FILES['uploadedfile']
How can I check that the form field contains a file before the rest of the script exicutes?
Thanks
Posted: Wed May 10, 2006 8:19 pm
by hawleyjr
The answer is in the variable.
Run this script and you'll answer your own question.
Code: Select all
echo '<HR><PRE>'; print_r($_FILES); echo '</PRE>';
Posted: Wed May 10, 2006 8:26 pm
by Jim_Bo
hawleyjr | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have tried a few ways, ie
Code: Select all
if ($_FILES['uploadedfile']['size'] > 0) {
echo "$back";
return;
}
But that just keeps taking me to the $back variable even when files have been added to the form
Thanks
hawleyjr | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Wed May 10, 2006 8:30 pm
by hawleyjr
That is because you're validating that the file is loaded...
Posted: Wed May 10, 2006 8:39 pm
by Jim_Bo
Hi,
Any othe clues, I thought that check if the file size is less that 0 etc
but that doesnt seem to work
Thanks
Posted: Wed May 10, 2006 8:59 pm
by hawleyjr
Jim_Bo wrote:Hi,
Any othe clues, I thought that check if the file size is less that 0 etc
but that doesnt seem to work
Thanks
Yes, but you are checking to see if the file size is
greater than zero...
Posted: Wed May 10, 2006 9:05 pm
by Jim_Bo
True that, but I tried both ways, but even when less than 0 or <= is chosen it still proceeds rather than echo $back
Thanks
Posted: Wed May 10, 2006 9:23 pm
by litebearer
Posted: Thu May 11, 2006 10:10 am
by bokehman
Code: Select all
if (!$_FILES['uploadedfile']['error'])
{
#a file was uploaded
}