I have a upload field where people can upload a image. I’d like to add a link next to it that says: use default
So when the user doesn’t have a image to upload they can click on the link that will set a specific file (on the webserver) for that field. For example: default_picture1.jpg
I’ve read that it’s not possible (for security reasons) to use javascript to set the value of a input file type. I understand the clientside security reasons but what I’m trying to achieve is setting the value with a file on the webserver which is already there that can be used when the guest doesn’t have a picture to upload.
I tried with js but obviously doesn’t work:
<label>Picture 1</label>
<input title="" size="60" id="pic1" name="pic1" type="file" />
<a href="#" onClick="document.getElementById('pic1').value = 'test1.jpeg';">test1</a>
<a href="#" onClick="document.getElementById('pic1').value = 'test2.jpeg';">test2</a>
<a href="#" onClick="document.forms['form_upload'].elements['pic1'].value = 'test3.jpeg';">test3</a>
(btw: I was just trying 3 different ways of setting the value in JS)
Maybe it’s possible to do it with php?
If you have another idea that has to do with this, please feel free to post.
I highly appreciate your help and taking time to answer!
Regards,
Gosa
You can not set due to the security. Imagine if you could set the file to some cookie file in user’s computer or any other personal information rich data.
I would simply have a button to click if user wants a default image which would contain an image near the button. You can retrieve the image if user click the button. It’s your imagination.