Skip to content

Instantly share code, notes, and snippets.

@claremarieciriaco
Created October 12, 2012 05:22
Javascript Code for Getting the full filepath in Mozilla FF
<script type="text/javascript">
function readFile(fileBrowser) {
if (navigator.userAgent.indexOf("MSIE")!=-1) {
readFileIE(fileBrowser);
} else if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Mozilla")!=-1) {
readFileFirefox(fileBrowser);
var fullPath = $('#uploadedFileName').val();
alert(fullPath); //fullPath = C:\Documents and Settings\Clare\My Documents\test.jpg
} else {
alert("Not IE or Firefox (userAgent=" + navigator.userAgent + ")");
}
}
//If the browser is Mozilla FF
function readFileFirefox(fileBrowser) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert('Unable to access local files due to browser security settings.');
return;
}
var fileName=fileBrowser.value;
document.getElementById("uploadedFileName").value=fileName;
}
//If the browser is IE
function readFileIE(fileBrowser) {
var fullPath = $('#uploadedFile').val();
if (fullPath != null) {
alert(fullPath ); //fullPath = C:\Documents and Settings\Clare\My Documents\test.jpg
$('#uploadedFileName').val(fullPath );
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment