Connecting Tech Pros Worldwide Help | Site Map

I want to send the whole path

Claus Mygind's Avatar
Familiar Sight
 
Join Date: Mar 2008
Posts: 173
#1: Sep 25 '09
I am working on a small page I want to use for myself at home. I am trying to load the name of a file along with it's path into and Ajax call but all I get is the file name. Here is the 4 attempts I have made:

I would like to get this value transmitted
C:\Documents and Settings\Claus\My Documents\Maps\tracks\Dandy Horse.gpx

but all I get is

Dandy Horse.gpx
or
Dandy%20Horse.gpx

Expand|Select|Wrap|Line Numbers
  1.   <head>
  2. <script type="text/javascript">
  3. <!--
  4.  
  5.     var GPXHttp;
  6.  
  7. function sendGPXFile()
  8. {
  9.     if (window.ActiveXObject) 
  10.     {
  11.         GPXHttp = new ActiveXObject("Microsoft.XMLHTTP");
  12.     }else if (window.XMLHttpRequest) {
  13.         GPXHttp = new XMLHttpRequest();
  14.     }
  15.     var url = "/ABC/apps/readGPX.exe?timeStamp=" + new Date().getTime();
  16.  
  17. //here are the 4 attempts
  18. //do I need to say that I tried each of these one at a time.
  19.     var queryString = document.getElementById("GPXinput").value;
  20.     var queryString = escape(document.getElementById("GPXinput").value);
  21.     var queryString = encodeURI(document.getElementById("GPXinput").value);
  22.     var queryString = encodeURIComponent(document.getElementById("GPXinput").value);
  23.  
  24.     GPXHttp.onreadystatechange = handleStateChange;
  25.     GPXHttp.open("POST", url, true);
  26.     GPXHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  27.  
  28. alert("input = "+document.getElementById("GPXinput").value+"  query="+queryString);
  29.  
  30.     GPXHttp.send(queryString);
  31. }
  32.  
  33. //-->
  34. </script>
  35.  </head>
  36. <body>
  37.   <input type="file" id="GPXinput" value="gpxfile" size="100" onclick="" /><br />
  38.   <input type="button" value="Send File" onclick="sendGPXFile();" />
  39.  </body>
  40.  
  41.  
  42.  
  43.  
ssnaik84's Avatar
Member
 
Join Date: Aug 2009
Location: Bengaluru, India
Posts: 119
#2: Sep 26 '09

re: I want to send the whole path


lt's not possible to get absolute file path from client side javascript.
you can get it from any server side scripting language.
i dont know.. whether server side javascript can handle this..
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#3: Oct 1 '09

re: I want to send the whole path


Why would you need the full path anyway? For uploading, you only need the file name which is why the full path is not available.
Claus Mygind's Avatar
Familiar Sight
 
Join Date: Mar 2008
Posts: 173
#4: Oct 2 '09

re: I want to send the whole path


Quote:

Originally Posted by acoder View Post

Why would you need the full path anyway? For uploading, you only need the file name which is why the full path is not available.

Since all the data is on one computer, I did not really want to move the file. I only wanted a reference to the file location so my backend program could open the file and process it.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#5: Oct 4 '09

re: I want to send the whole path


When you upload, the server-side code will have access to the full path. Of course, you can just ignore the file. The other option is to give the user a field to enter the path, but that's not as intuitive as selecting the folder/file.
Reply


Similar JavaScript / Ajax / DHTML bytes