asmith Posted August 20, 2008 Share Posted August 20, 2008 I'm trying to get an image from the user in a form. If the form has error like he hasn't type his email, the form is viewed again but his last correct entries is still there, like : <input name=email value=$_POST /> how can i keep the image he had uploaded ? what that will be for the "<input type=file" ? Link to comment https://forums.phpfreaks.com/topic/120521-keeping-file-in-form-to-save-after-correction/ Share on other sites More sharing options...
s1yman Posted August 20, 2008 Share Posted August 20, 2008 if (isset($_FILES['image']) { $image = $_FILES[image]; print '<input type="file" value="'; print $image; print '" name="image" /> } else { print 'put the original form here'; } Is that what you mean? Link to comment https://forums.phpfreaks.com/topic/120521-keeping-file-in-form-to-save-after-correction/#findComment-621058 Share on other sites More sharing options...
PFMaBiSmAd Posted August 20, 2008 Share Posted August 20, 2008 When the form processing code ends execution, the temporary uploaded file is automatically deleted by php. Your code would need to save the uploaded file somewhere (session, file...). The type="file" value is read only (and if you could put the file name in it, you would be wasting your bandwidth because the same file would be uploaded each time the form gets submitted.) Link to comment https://forums.phpfreaks.com/topic/120521-keeping-file-in-form-to-save-after-correction/#findComment-621059 Share on other sites More sharing options...
asmith Posted August 20, 2008 Author Share Posted August 20, 2008 is there a way i get the address of the file on the users computer, so that I put his address in that field again? @s1yman : what is $image actually there? Link to comment https://forums.phpfreaks.com/topic/120521-keeping-file-in-form-to-save-after-correction/#findComment-621062 Share on other sites More sharing options...
PFMaBiSmAd Posted August 20, 2008 Share Posted August 20, 2008 No, you can't. For security reasons, the file field can only be filled in by the browser. Javascript and HTML/php cannot put a value in. Link to comment https://forums.phpfreaks.com/topic/120521-keeping-file-in-form-to-save-after-correction/#findComment-621063 Share on other sites More sharing options...
s1yman Posted August 20, 2008 Share Posted August 20, 2008 @s1yman : what is $image actually there? Hold on, theres a chance I'm being an idiot. . . let me just try it Link to comment https://forums.phpfreaks.com/topic/120521-keeping-file-in-form-to-save-after-correction/#findComment-621064 Share on other sites More sharing options...
asmith Posted August 20, 2008 Author Share Posted August 20, 2008 So ... I don't want to ask the user to upload again, How to store it in session? or if i save the file somewhere and user leave my form, How to find it out? I mean I can think of someways to do it, like I store a variable in a session, if the form didn't submit, then checking that variable of the session, so i delete the file, but is that the standard way? What most people do in these cases? Link to comment https://forums.phpfreaks.com/topic/120521-keeping-file-in-form-to-save-after-correction/#findComment-621067 Share on other sites More sharing options...
s1yman Posted August 20, 2008 Share Posted August 20, 2008 how about employing a second form, solely to upload the image? It can carry the data over from the first form once it is complete. That would save a lot of scripting and bandwith when there is problems. Link to comment https://forums.phpfreaks.com/topic/120521-keeping-file-in-form-to-save-after-correction/#findComment-621071 Share on other sites More sharing options...
asmith Posted August 20, 2008 Author Share Posted August 20, 2008 The best I guess is to store the file in a session. So that session expire if user do not submit. How can i store a file in a session? Link to comment https://forums.phpfreaks.com/topic/120521-keeping-file-in-form-to-save-after-correction/#findComment-621087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.