Scooby08 Posted December 10, 2008 Share Posted December 10, 2008 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 More sharing options...
Brian W Posted December 10, 2008 Share Posted December 10, 2008 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. Link to comment https://forums.phpfreaks.com/topic/136409-keep-post-data-with-upload-file-field/#findComment-711796 Share on other sites More sharing options...
PFMaBiSmAd Posted December 10, 2008 Share Posted December 10, 2008 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. Link to comment https://forums.phpfreaks.com/topic/136409-keep-post-data-with-upload-file-field/#findComment-711808 Share on other sites More sharing options...
Brian W Posted December 10, 2008 Share Posted December 10, 2008 if the upload function work, make a session variable store the filename then, if there is an issue and they go back to the page, if the session with the filename isset, then don't show the file input. Link to comment https://forums.phpfreaks.com/topic/136409-keep-post-data-with-upload-file-field/#findComment-711813 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.