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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

browse functionality for retreiving location of file

Status
Not open for further replies.

Mariootje

Programmer
Aug 10, 2001
33
NL
Hi there,

For my application I want users to be able to browse to the location of a file they want to upload. Because of the size of the file I don't really want to upload the file, but only the location of the file.

Is there a way to send the location of the file to the server (and not upload the file) when clicking the submit button?

Many thanks in advance!

Mario
 
This would be a possible scheme.
[1] Statically or dynamically create an input element of file type. Make the onchange handler to write the value to the hidden control [2].
[2] Script a hidden type input to store the info upon onchange handling of the control [1].
[3] Script the onsubmit handler to dynamically remove the control [1].
 
I think the full path would not normally, without especially written out, be sent back to server as a measure of protecting privacy, only the file name would be sent over.
 
After the client browses to and selects a file the full path and filename can be accessed in Javascript and stored into a hidden form field as tsuji suggested.

If the input field for the file browse is dynamically generated though you can run into an IE bug where you cannot access the properties of the field using it's name and you have to actually loop through the form elements to obtain it. Here is the code I use.

Code:
function getFieldValue(fieldName) {
  var form=document.getElementById('myform');
  if (!document.all)
    return form[fieldName];
  else  // IE has a bug not adding dynamically created field as named properties so we loop through the elements array to get the name.
    for (var e = 0; e < form.elements.length; e++) {
      if (form.elements[e].name == fieldName)
        var fieldvalue = form.elements[e].value;
      if (fieldvalue == "")
        fieldvalue = "none";      
    }
  return fieldvalue;
}

You cannot use the path\name in order to perform an upload for that to happen you have to access the object created by the input field so you cannot just pass the path\name to a processing page in order to perform the upload, you have to submit the form directly so the object is available.


At my age I still learn something new every day, but I forget two others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top