Page 1 of 1

Get File Path

Posted: Mon Mar 23, 2009 7:43 pm
by Anarking
Hi there

Im trying to get the file path from a browse button so that I can send it to a php class to parse its contents


Currently I have this


<form name="someform" action="test2.php" method="post">
<input type="file" name="FileName" size="chars">
<input type="submit" />
</form>


But all it gives me is the filename itself

How do I get the path of the file?

For example C:\Test.txt rather then just Test.txt?

Thanks

Re: Get File Path

Posted: Mon Mar 23, 2009 7:54 pm
by requinix

Re: Get File Path

Posted: Mon Mar 23, 2009 8:16 pm
by Anarking
hmmmm


Still only gets the file name...

Re: Get File Path

Posted: Mon Mar 23, 2009 8:24 pm
by requinix
Then what's your code?

Re: Get File Path

Posted: Mon Mar 23, 2009 8:27 pm
by Anarking
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="test2.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="attachment" type="file" />
<input type="submit" value="Send File" />
</form>


And my test2.php is


<?php



echo "The other file is ".$_POST['attachment'];

?>

Re: Get File Path

Posted: Mon Mar 23, 2009 8:37 pm
by requinix
tasairis wrote:Read.
Try that again. Pay attention to the bits that mention the $_FILES array.

Re: Get File Path

Posted: Mon Mar 23, 2009 10:34 pm
by sputnik
access the value through JS

Re: Get File Path

Posted: Mon Mar 23, 2009 10:43 pm
by Christopher
When you upload a file it is placed in a temporary file that will be deleted when the script is done. $_FILES['userfile']['tmp_name'] holds the full path to the temp file. You must use move_uploaded_file() to move the file to the place that you want it. You may use the original name of the file (contained in $_FILES['userfile']['name']) to give the temp file a name -- or name it yourself to whatever you want.

Re: Get File Path

Posted: Tue Mar 24, 2009 8:09 am
by Anarking
Yeah, thanks guys. Got it working now.


Not the way I originally intended to do it but it works all the same.