Jump to content

Recommended Posts

Greetings!

 

I'm coding a page form and to prevent its fields to be reset, I have to echo the POST values back into their respective form fields.

 

It is working well for text inputs but I am having problem with an file input type. Echo-ing the POST value back does not work: the respective form field resets, is blanked out...no matter what!!

 

This is my code...

 

... <input tabindex="23" type="file" name="myfile" value="<?php echo $_FILES['myfile']['name'];?>" /><br>...

 

What I am doing wrong??  Can someone please tell me?!

I'm not sure if you are going to be able to do that with an INPUT of type FILE.  The value shown when the user selects a file is the full pathname to the file ON THEIR COMPUTER.  The data you get when it posts as the 'name' is just the filename (you do not get the drive and path).  If you do echo the name back to the form, it will not necessarily represent the same file since it will not contain a path.  I have not tried this, but I suspect that some (if not all) browsers will ignore whatever you provide since it could be ambiguous (at best).

 

After you get the page loaded, look at the page source and see if the value is there in the INPUT element.  If it is, then you know you are sending it and the browser is ignoring it.  If it is not there, it could mean that the browser is ignoring it completely (and not even including it in the page source).

 

All in all, I don't think you can accomplish what you are trying to do for this type of field.  On the other hand, I have never tried it, so I can't say for sure.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.