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
obtaining clients source file path in fileuploading...
Moderator: General Moderators
Re: obtaining clients source file path in fileuploading...
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.
- 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...
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...
I tried this code, but its displaying only the file name instead of absolute path from the clients side. thanks for the quick reply.
- 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...
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.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.
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...
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.iankent wrote: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.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.
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?)
Thanks a lot for your kind help.