--- bryan_is_south <[EMAIL PROTECTED]> wrote:

> > Hi Brian,
> >              An error for echo($_FILES['upload']['name']); does not 
> > necessarily mean that there is no $_FILES superglobal.
> > 
> > The above assumes that you are using a form with <input type="file" 
> > NAME="upload">
> > 
> > Try this
> > 
> > if(!is_set($_FILES))
> >   {
> >   echo("There are no files uploaded\n");
> >   die();
> >   }
> > foreach($_FILES as $key => $thisfile)
> >   {
> >   echo("For the form input name that is [" . $key . "]\n\n");
> >   echo("Remote file (name) is [" . $thisfile['name'] . "]\n");
> >   echo("Browsers suggested mime (type) is [" . $thisfile['type'] .
> "]\n");
> >   echo("Actual file (size) is [" . $thisfile['size'] . "]\n");
> >   echo("Server temporary name (tmp_name) is [" .
> $thisfile['tmp_name'] . 
> > "]\n");
> >   echo("Upload (error) is [" . $thisfile['error'] . "]\n\n\n\n");
> >   }
> >
> 
> ---
> 
> Thanks for the codes.
> The first isset() part seems to show that the $_FILES is there, but
> the foreach loop doesn't go through.  It doesn't even begin the loop.
> That doesn't really make sense, but somehow, there is the $_FILES
> superglobal, but it can't loop through them.
> Is this normal?
> 
> Thanks

I would not be surprised if the $_FILES superglobal is created for each HTTP
request in PHP even if no files have been uploaded.  You would want to check to
see that both $_FILES is_set() and see if count($_FILES)>0 that way you would
know that there was at least one element in the array.

Sometimes foreach() will throw a warning if the variable is not an array. 
Whether you see this will depend on your PHP configuration.

Also, the die() function accepts an argument...the message to be printed before
stopping the program so you could use:

die("There are no files uploaded.");

instead of your two-line version above.

For testing, why not keep it really simple?:

if (is_array($_FILES) and count($_FILES))
{
 printf("<pre>%s</pre>", print_r($_FILES, true));
}

This should show you the array $_FILES and you can tell pretty readily if there
is any data there.

Common errors for uploading files involves the original <form> tag and <input>
tag.  You have to define the enctype='multipart/form-data' in the <form> tag. 
The <input> tag should be type='file'.  The name property of the <input> tag
determines where in the $_FILES superglobal the rest of the data may be found
(the array key).

James
 

Reply via email to