obtaining clients source file path in fileuploading...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
naveen519
Forum Newbie
Posts: 3
Joined: Sun Oct 12, 2008 11:38 am

obtaining clients source file path in fileuploading...

Post by naveen519 »

Hii all,

How can i store the source file path from the clients system to the servers database. wherein i can able to upload the file from client, instead of that i want the source path of the file from where the file is being uploading.

Please help,

Thanks in advance
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: obtaining clients source file path in fileuploading...

Post by pickle »

You can't. That information is never transmitted to the server.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: obtaining clients source file path in fileuploading...

Post by iankent »

You can do it using javascript, but if javascript is disabled then the path won't be sent (though the file still will). Here's an example:

Code: Select all

 
<?php
  if(isset($_POST['filesrc'])) {
        echo "File source was: ".$_POST['filesrc']."<p />";
  }
?>
 
<script>
function procfile() {
    var e = document.getElementById("myfile");
    var e2 = document.getElementById("myfilesrc");
    e2.value = e.value;
    document.myform.submit();
}
</script>
 
<form name="myform" action="?" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="myfile" />
<input type="hidden" name="filesrc" id="myfilesrc" />
<input type="button" value=" Submit " onclick="procfile(); return false;" />
</form>
 
naveen519
Forum Newbie
Posts: 3
Joined: Sun Oct 12, 2008 11:38 am

Re: obtaining clients source file path in fileuploading...

Post by naveen519 »

I tried this code, but its displaying only the file name instead of absolute path from the clients side. thanks for the quick reply.
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: obtaining clients source file path in fileuploading...

Post by iankent »

naveen519 wrote:I tried this code, but its displaying only the file name instead of absolute path from the clients side. thanks for the quick reply.
it may depend on the browser, not too sure. the code sample I provided does provide the full file path, at least on Vista x64 Firefox 3.5.

Unfortunately, if the info isn't provided by the browser then the javascript won't be able to retrieve it and pass it on to PHP, so if my code sample is only returning the file name then that's a browser issue (possibly as a form of security to prevent this kind of javascript finding out info about a users computer?)
naveen519
Forum Newbie
Posts: 3
Joined: Sun Oct 12, 2008 11:38 am

Re: obtaining clients source file path in fileuploading...

Post by naveen519 »

iankent wrote:
naveen519 wrote:I tried this code, but its displaying only the file name instead of absolute path from the clients side. thanks for the quick reply.
it may depend on the browser, not too sure. the code sample I provided does provide the full file path, at least on Vista x64 Firefox 3.5.

Unfortunately, if the info isn't provided by the browser then the javascript won't be able to retrieve it and pass it on to PHP, so if my code sample is only returning the file name then that's a browser issue (possibly as a form of security to prevent this kind of javascript finding out info about a users computer?)
Yeah., It's the problem with the firefox 3.5.5. I have found the result as absolute path when i have tested this sample code in IE.

Thanks a lot for your kind help. :D
Post Reply