$_FILES['uploadedfile']

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

Post Reply
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

$_FILES['uploadedfile']

Post 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
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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>';
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

hawleyjr | Please use

Code: Select all

,

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

,

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]
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

That is because you're validating that the file is loaded...
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post 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
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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...
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post 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
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Post by litebearer »

User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Code: Select all

if (!$_FILES['uploadedfile']['error'])
{
   #a file was uploaded
}
Post Reply