Welcome to WebmasterWorld Guest from 54.167.46.29

Forum Moderators: open

Message Too Old, No Replies

Setting default value for file upload form

Not supported by IE and FF, only by Opera?

     
9:02 pm on Dec 19, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Feb 4, 2004
posts:305
votes: 0


I want to fill in a default filename for a file upload form.

<input type="file" size="35" name="imgupload" value="a:\\image.jpg">

But it seems this is only supported by Opera and Opera ask for a confirmation. It doesn't work in IE or FF.

Is there anyway to go around this, e.g. using javascript? It is ok when the user has to click the filename before it is being filled-in in the input box.
So maybe I had to post this in the Javascript forum, but I'm hoping there is way to do it without using Javascript.

I want to use this for a form in which the user can type in or upload some HTML text and via a PHP script I want to scan the text for IMG tags so the user can easily upload the images after the HTML text has been uploaded.

Thanks,

Arjan

2:46 am on Dec 20, 2005 (gmt 0)

Senior Member from CA 

WebmasterWorld Senior Member encyclo is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 31, 2003
posts:9063
votes: 2


As you have seen, only Opera supports this. The HTML4 specifications [w3.org] suggest:

User agents may use the value of the value attribute as the initial file name.

But in reality it is pretty unworkable: there are two distinct problems, the first being security (hence the confirmation step in Opera, else confidential information could unwittingly be uploaded). The second problem is platform differences: I run Linux, so there is no a:\ path - you can't reliably second-guess a file's location.

You might want to check out Jukka Korpela's (as always) very comprehensive guide:

[cs.tut.fi...]

7:51 am on Dec 20, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Feb 4, 2004
posts:305
votes: 0


Hi encyclo,

Thanks for your answer. I'm aware of possible security issues and the Linux 'problem', my idea was to ask the user for a default path to the images and prepend that for each filename.

I already did some testing with javascripting but I think it is almost impossible to do. What I did was the following:

<input id="fileinput" type="file" size="35" name="imgupload" value="a:\image.jpg">

<a href="#" onlick="fileinput.value='a:\image.jpg'; return false;">a:\image.jpg</a>

In this case the user can click the filename from a list extracted from the HTML test which will be inserted in the input box. But this also doesn't work. Another thing I tried was this:

<input id="fileinput" type="text" size="35" name="imgupload" value="a:\image.jpg">

<a href="#" onlick="fileinput.type='file'; return false;">a:\image.jpg</a>

This also doesn't work, as soon as the link is clicked, a 'Browse' button appears but also the box is emptied.

As for now I have no idea how to solve this apart from displaying a list of filenames and the user has to select and copy and paste them in the input box.

Arjan