Get File Path

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Anarking
Forum Newbie
Posts: 24
Joined: Wed Feb 11, 2009 11:29 am

Get File Path

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Get File Path

Post by requinix »

Anarking
Forum Newbie
Posts: 24
Joined: Wed Feb 11, 2009 11:29 am

Re: Get File Path

Post by Anarking »

hmmmm


Still only gets the file name...
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Get File Path

Post by requinix »

Then what's your code?
Anarking
Forum Newbie
Posts: 24
Joined: Wed Feb 11, 2009 11:29 am

Re: Get File Path

Post 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'];

?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Get File Path

Post by requinix »

tasairis wrote:Read.
Try that again. Pay attention to the bits that mention the $_FILES array.
User avatar
sputnik
Forum Newbie
Posts: 2
Joined: Mon Mar 23, 2009 8:09 pm

Re: Get File Path

Post by sputnik »

access the value through JS
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Get File Path

Post 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.
(#10850)
Anarking
Forum Newbie
Posts: 24
Joined: Wed Feb 11, 2009 11:29 am

Re: Get File Path

Post by Anarking »

Yeah, thanks guys. Got it working now.


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