NYCPHP Meetup

NYPHP.org

[nycphp-talk] $_FILES and form reloading

David Krings ramons at gmx.net
Sat Nov 11 11:50:45 EST 2006


Hi,

    my guess is that one cannot easily pass back a file name to a form, 
mainly because the file input element doesn't let one do anything at 
all. It is a pure client side only controlled user interface element.

    I can think of two ways assuming that the file itself is OK, just 
some other info isn't.

a) secure the uploaded file and don't show the file input element at all 
on a reload
b) show an empty file input element and display a note that the user 
doesn't have to browse for the file again
c) instead of showing a file input element show a text box and a 
customer button that says "Browse...", but is disabled - sort of faking 
the looks of a disabled file input element

I faced the same problem not too long ago and chose a). There isn't any 
reason to show the file name again or have the user select a file again 
(and possibly select a wrong file this time as the user may think that 
is the source of the problem). I am sure that the problem is simply the 
dumb file input element that doesn't let you do anything. You can't even 
set the file types to be allowed.

    David K.

Michael Southwell wrote:
> I have run into a problem with the $_FILES global and reloading a 
> form when the user has omitted required information. Reloading the 
> $_POST variables is no problem. But the form among other things 
> offers the user a chance to upload a photo, and it is reloading that 
> $_FILE information where I'm not succeeding. The relevant code is this:
>
> <input name="photo1" type="file" class="style1" value="<?= 
> $_FILES['photo1']['name'] ?>" />
>
> print_r( $_FILES ) shows that $_FILES['photo1']['name'] exists, but 
> it's not being shown in the input field.  What am I doing wrong?
>
> Further than that, the name that exists is not fully qualified, so 
> even if it were being displayed, I presume it wouldn't do any good 
> upon the eventual successful submission of the form. How can I solve that?
>
> By the way, it all works perfectly when the form doesn't need to be reloaded.
>
>   



More information about the talk mailing list