To get the full path of an uploaded file

guys,
is there a way by which i could get the full path of an uploaded file and store it in a variable?..i did this…
$file123=$_FILES[‘file1’][‘name’];

i upload my file this way:

<input type=“file” name=“file1”/>
<input type=“hidden” name=“MAX_FILE_SIZE” value=“30000” />

but got the original name of the file on the client machine…i need to have the complete path not just the name…kindly help.

You must use then JavaScript to get the full path of file in the client computer.

Try this:

<input type="file" name="file1">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">

And put this Javascript function between the headtags.

<script language="javascript" type="text/javascript">
function getPath() {
     var inputName = document.getElementById('file1');
     var imgPath;

     imgPath = inputName.value;
     alert(imgPath);
}
</script>

And the forms onSubmit value put the function name;)

i didnt get wat u mean by “And the forms onSubmit value put the function name” plz clarify…im a novice…

you must put to the form tag like this:

<form name="frm" method="post" action="some_url" onSubmit="getPath();">
...
</form>

If the form is being submitted, then it’s alerts you the path of the image…

well friend thanks…uptil now. a step further… i need to store the value of the javascript variable imagePath in the mysql database…how do i do that ?. if it was a php variable…it would be simple…by the way is it possible to store the value of a javascript variable, imagePath into a php variable…so that i can then save it in the database?

ok, I made something…but this is not tested…

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>This is a test</title>
<script language="javascript" type="text/javascript">
function getPath() {
var inputName = document.getElementById('file1');
var imgPath;

imgPath = inputName.value;
document.getElementById('file_src').value = imgPath;
}
</script>
</head>

<body>
<form name="frm_upload" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" onSubmit="getPath();">
<input name="file1" type="file"><br>
<input name="file_src" type="hidden" value="">
<input name="btn_submit" type="submit" value="show path">
</form>
<?php
	echo stripslashes($_POST["file_src"]);
?>
</body>
</html>

ok, now I made a few changes…this is also other browsers compatible too.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>This is a test</title>
<script language="javascript" type="text/javascript">
function getPath() {
var Form = document.forms['frm_upload'];
var inputName = Form.elements['file1'].value;

var imgPath = inputName;
Form.elements['file_src'].value = imgPath;
}
</script>
</head>

<body>
<form name="frm_upload" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" onSubmit="getPath();">
<input name="file1" type="file"><br>
<input name="file_src" type="hidden" value="">
<input name="btn_submit" type="submit" value="show path">
</form>
<?php
	echo stripslashes($_POST["file_src"]);
?>
</body>
</html>

thanku so much…grateful to u…it works fine