Page 1 of 1
obtaining clients source file path in fileuploading...
Posted: Tue Nov 24, 2009 3:09 am
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
Re: obtaining clients source file path in fileuploading...
Posted: Tue Nov 24, 2009 9:57 am
by pickle
You can't. That information is never transmitted to the server.
Re: obtaining clients source file path in fileuploading...
Posted: Tue Nov 24, 2009 10:08 am
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>
Re: obtaining clients source file path in fileuploading...
Posted: Wed Nov 25, 2009 6:54 am
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.
Re: obtaining clients source file path in fileuploading...
Posted: Wed Nov 25, 2009 9:39 am
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?)
Re: obtaining clients source file path in fileuploading...
Posted: Thu Nov 26, 2009 2:22 am
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.
