Jump to content

Keep Post Data with upload file field


Scooby08

Recommended Posts

Say I have this input:

 

<input type="file" name="userfile" width="55" />

 

Is there a way to keep the path to whatever file they chose to upload in the field after they submit and there is an error? Maybe something like this, but this does not work..

 

<input type="file" name="userfile" value="<?=$_POST['userfile'];?>" width="55" />

Link to comment
https://forums.phpfreaks.com/topic/136409-keep-post-data-with-upload-file-field/
Share on other sites

maybe javascript, but I don't know for sure.

theory-

onchange="make hidden field value == to the upload form value"

store that field as a session val and echo it in the upload form so that if they are sent back to that page for whatever reason, the path is their again.

like it said, don't even know if that would work but worth messin with if you know js.

The type="file" field is read only. The only way to put something into it is through the browser's file selection input box.

 

Even if you could put what they entered back into the field, once they submit the form that file is uploaded. Putting the file name back into the field would cause the file to be uploaded again, wasting time for the visitor and wasting your bandwidth.

 

When they submit the form, process the uploaded file, even if there are other errors on the form. Or have a multi page form where the last page is the upload and you can only get to the last page if there are no errors in the post data.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.