kristo5747 Posted April 8, 2010 Share Posted April 8, 2010 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?! Quote Link to comment https://forums.phpfreaks.com/topic/198016-form-reset-post-value-to-file-input-type-fails/ Share on other sites More sharing options...
DavidAM Posted April 8, 2010 Share Posted April 8, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/198016-form-reset-post-value-to-file-input-type-fails/#findComment-1039069 Share on other sites More sharing options...
kristo5747 Posted April 8, 2010 Author Share Posted April 8, 2010 Mmm....your explanation makes sense... Thanks for your input. Quote Link to comment https://forums.phpfreaks.com/topic/198016-form-reset-post-value-to-file-input-type-fails/#findComment-1039111 Share on other sites More sharing options...
the182guy Posted April 8, 2010 Share Posted April 8, 2010 No can't be done. Why? Security - because if it was possible then you could easily create malicious PHP or Javascript code to steal files from a users computer. Quote Link to comment https://forums.phpfreaks.com/topic/198016-form-reset-post-value-to-file-input-type-fails/#findComment-1039171 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.