get the full file path of file input field

V

Vibhu

Hello All,

I have a input box on the HTML page with the type set to file. What I
want is that when the value changes in the file textbox, it should give
me the full file path. I have even tried passing the value to a hidden
control but all it does is passes only the File Name and not the file
path.

How do I go about it. I tried checking GMAIL service (Compose Mail) but
all I could get is that they are passing the window and the file object
to a function, the code of which is not accessible.

Any help will be greatly valuable.

Regards,

Vibhu Bansal.
 
A

admataz

Hi Vibhu

what you're trying to do probably not allowed because of security
restrictions of the browser sandbox. If the browser or web page were
given access to the contents or filepaths of the client machine it
could used maliciously. You don't need to know the filepath to send the
file to the server - the browser will attach and send the file to the
form data.

regards,
-ad
 
V

Vibhu

Hi,

The reason why I want the full path of the file is that I want the file
to be uploaded in the background while the user is still on the
webpage; just the way GMAIL is attching files. I am sure using AJAX
this can be achieved.

So what I want is that the GET method of the .html page is invoked in
the background that will upload the file from the client to the server.

Hope this helps.

Regards,

Vibhu Bansal.
 
V

Vincent van Beveren

Hi Vibhu,

A submit action can have a target attribute. What you could do is create
a hidden IFRAME, make the FORM target the name of the IFRAME. When a
user clicks submit, the file will be uploaded outside the page the form
is on. Clear the form and the user can uload another one.

So:

<form id="uploadForm" ... other tags...>
<input type="file" name="upload">
<input type="button" value="Attach" onclick="upload()">
</form>

... javascript:

var frameIndex = 0;

function upload() {
myFrame = document.createElementId("IFRAME");
myFrame.name = 'frame' + frameIndex;
// ... make IFRAME hidden
document.body.appendChild(myFrame);
form = document.getElementById("uploadForm");
form.target = 'frame' + frameIndex;
form.submit();
frameIndex++;
}

Something like that. I have never done it, but it should work in theory.
Also note that if you exit the window all uploads that are busy are
cancelled, so you should wait for the myFrame.contentWindow.onload to be
triggered before you can leave the page.


Good luck,
Vincent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top