Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File object retained in Form

Status
Not open for further replies.

JimFL

Programmer
Jun 17, 2005
131
GB
Hi,

Can anybody suggest the best way to retain a file form object within a form that is submitted part way through a process to gain extra form information. Then it is submitted at the end to save the form data.

So in other words I can keep other text box data by this method:

<input type="text" name="name" value="<?php if(isset($_POST['name'])){ echo $_POST['name'];}?>" >


for the file object could it be done? , this below doesnt work:


<input name="imagefile" id="imagefile" type="file" value="<?php if($_FILES['imagefile']['tmp_name']!=""){print($_FILES['imagefile']['tmp_name']);}?>">


has anybody got a solution to temporarily store the data and then send on a second time - or is it not possible?

Please help.

Thanks

JimFl

 
seems a bit odd to require the user to upload the same file twice. after the first upload why don't you just store the resultant file in the server's filesystem somewhere and store the location of the file either in a session variable or, if you must, in a hidden text field on a form sent to the client.
 
Im open to ideas - but ideally I dont actually want to save the file until the second submit. The first submit builds in some extra components to the form and will be submitted all together at the end.

is there a way to do this?


 
For security purposes, prefilling the input file type is not allowed. Just think about it -- if someone could prefill the file type and then either hide it or send the form automatically, users could be uploading any file the person wanted from their computer to the website. That would be a serious security hole.
 
Ok Im a bit confused as the security issue -

Essentially I was submitting the form to add in a further 3 form fields. Maybe I should just do this with javascript rather than using the form submit. That way the form will only be submitted once at the end.



 
Anytime the file input has a value in it, it attempts to upload the associated file with the form submit. That means that whether or not you want it to upload the first time, it's going to. If you find some way to fill that on the second form, it's going to upload again whether or not you processed the value the first time. In my book this is bad, because dependant on the file size and users connection they could be sitting their for a fairly long page load while the file re-uploads. (Apologies to jpadie for the reitiration)

Why not get the file on the first upload and then output something that looks like the file upload on the second form. Like a disabled text input and button? This way they only sit through one upload, the data is still visibly on the page on the second form, but you don't add any overhead to the second form submission and don't add any complexity to the second form load.

-T

barcode_1.gif
 
Thanks for your help, I will certainly bear that in mind for future projects. Hwoever I have simplified the form to use javascript to add extra fields. I did this by toggling the visibility style of a table element that contained the form component.


Then the user only has to upload the form once rather than twice.

Thanks

Jimfl


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top