Forum Moderators: coopster

Message Too Old, No Replies

echo into a <input type="file" name="file" />

is it possible

         

diegomh7

7:41 pm on Aug 2, 2006 (gmt 0)

10+ Year Member



HOWDO ALL!

im working on something for a client some CMS stuff, they want to edit images.

how it works,

admin_edit.php > loads a bunch of empty fields followed by a list of products vertically.

The user clicks one of the products form the list and the page reloads, filling the fields from a mysql DB table.

Problem is, when we load the info and echo it into the boxes on the screen, the input type file doesnt write anything in, so when we go to update the changes unless weve found the images on the HD again the field in the DB gets wiped out and the product pictures will dissapear.

is it possible to echo results into a files input type?

any other ideas besides throwing the laptop away?

thanx in advance

diegomh7

dreamcatcher

7:49 pm on Aug 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi diegomh7,

If all you are concerned about is the file name, can you not just assign it to a hidden field?

dc

supermoi

1:57 am on Aug 3, 2006 (gmt 0)

10+ Year Member



It is not possible to put the correct value inside the input since you don't know the path on the person's hard drive, and even if you did, you'd have no guarantee it's still there.
However, once the form is submitted, you can easily test if a file was submitted, and then replace the current file with the new one.

From php.net:

If no file is selected for upload in your form, PHP will return $_FILES['userfile']['size'] as 0, and $_FILES['userfile']['tmp_name'] as none.

john_k

3:23 am on Aug 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You cannot preset the value for a FILE input field, nor can you set its value with javascript. This is a security measure. If you were able to do these things, then it would be quite easy to steal files from people's harddrives. (as in a web page loads a form in a hidden iframe and grabs your Windows registry database or an outlook pst file without you ever knowing about it)

diegomh7

2:33 pm on Aug 3, 2006 (gmt 0)

10+ Year Member



good good and bad bad to the people who would think of stealing such info :)

so basically we cant auto fill the file box, oki dokey ill get them to make image changes form a seperate page,

regards,

Diegomh7

diegomh7

2:35 pm on Aug 3, 2006 (gmt 0)

10+ Year Member



DC thanc good idea also, done that for another site but cam across probs when sending through the hidden fields and the files 1 and files 2 input fields, bit of jiggery pokery with the if this then this $var = this kind of thing.

thanx everyone, hope this post helps someone else out in the future,

diegomh7