PHP/web programming get full local path of a file
PHP/web programming get full local path of a file
Author
Discussion

shocker-z

Original Poster:

554 posts

249 months

Sunday 28th January 2007
quotequote all
Is there a way to see the local path of a file that a user is trying to upload?
I'm wanting to know this because im wirting a script to generate a INI file which includes absolute paths to files on a system.


So for example if i chose to upload a file off my computer "C:\program files\testfolder\testdatabase.mdb" then i can locate that using the file browser on the page and when i submit i can use that path as a variable to enter into the INI in which im creating.

I've looked in just PHP but there isn't a way but anyone any ideas of how i could transfer the path to another variable with javascript?


Regards
Liam

TangoAlpha

1,175 posts

285 months

Sunday 28th January 2007
quotequote all
Does this page help?

GreenV8S

31,027 posts

315 months

Sunday 28th January 2007
quotequote all
If you're willing to rely on client-side script you could read the file name from the input field and return it separately, like this.

Bodo

12,620 posts

297 months

Sunday 28th January 2007
quotequote all
I've once uploaded my stuff to a recruitment site, and I was astonished to find the full path from my machine as the (online-)filename afterwards, i.e. /home/bodo/cv.pdf
I wonder if it just became buggered by the slashes of the Unix notation, as it possibly awaited a backslash to separate the actual file name.

shocker-z

Original Poster:

554 posts

249 months

Sunday 28th January 2007
quotequote all
TangoAlpha said:
Does this page help?


Unfortunatly PHP can't return the entire path of client machine it's just shows the filename it self

GreenV8S said:
If you're willing to rely on client-side script you could read the file name from the input field and return it separately, like this.


seems like this is the only way to go at the moment. One good this is that javascript has to be enabled for the actual application that im writing the INI generator for anyway so should work as all are running IE


Bodo said:
I've once uploaded my stuff to a recruitment site, and I was astonished to find the full path from my machine as the (online-)filename afterwards, i.e. /home/bodo/cv.pdf
I wonder if it just became buggered by the slashes of the Unix notation, as it possibly awaited a backslash to separate the actual file name.


Sound like a bug to me mate it should see the file uploaded rather than the patch to be honest as ytou can see im trying to get that bug but no one knows how lol


Thanks
Liam

TangoAlpha

1,175 posts

285 months

Sunday 28th January 2007
quotequote all
Try this:

<?php

Header("Content-type: text/html";

echo "<html> <body> ";

if(isset($_POST['action']))
{
echo $_POST['clientfile'];
}
else
{
echo "<form name='fileform' action='test.php' method=post> ";
echo "<input type='file' name='browsefile' size=50> ";
echo "<input type='hidden' name='action' value=1> ";
echo "<input type='hidden' name='clientfile'> ";
echo "<input type='submit' name='Upload file' onclick='fileform.clientfile.value=fileform.browsefile.value'> ";
echo "</form> ";
}

echo "</body> </html> ";

?>

TangoAlpha

1,175 posts

285 months

Sunday 28th January 2007
quotequote all
Oh well, that looked a lot better in preview rolleyes

Replace & gt and & lt for angle brackets and hopefully it should make sense.

TangoAlpha

1,175 posts

285 months

Monday 29th January 2007
quotequote all
Another try to get it formatted correctly...

<?php

Header("Content-type: text/html ";

echo "<html> <body> ";

if(isset($_POST['action']))
{
echo $_POST['clientfile'];
}
else
{
echo "<form name='fileform' action='test.php' method=post> ";
echo "<input type='file' name='browsefile' size=50> ";
echo "<input type='hidden' name='action' value=1> ";
echo "<input type='hidden' name='clientfile'> ";
echo "<input type='submit' name='Upload file' onclick='fileform.clientfile.value=fileform.browsefile.value'> ";
echo "</form> ";
}

echo "</body> </html> ";

?>

TangoAlpha

1,175 posts

285 months

Monday 29th January 2007
quotequote all
That's a bit better. Anywhere there is a gap between quotes it should be "slash" n, and I don't think php has a command