Getting the file path on the user system when submitting a file

So basically this all started with this e-mail to my local mailing list:
” I have this code

get file

if ($myfile)
print “myfile = “.$myfile;

When I browse to a file, say /tmp/thisfile.txt, the code returns only the name of the file, not the full pathname to the file. What am I doing wrong? Help!”

So after a little research I realised that the file name alone is uploaded, not the file path, which is what was causing the error. So the solution devised was sent in the following email back to the mailing list:
“Here’s your workaround:
Basically since when you POST only the file name and not it’s path is
posted, what I did is create a hidden text field which copies the
entered data in the file field BEFORE the POST occurs (using a little
I tested it on my system and it seems to work except for the double
slashes (//) being set on the file names, which could be a Windows
thing, but this is easily removable with a little more javascript text
manipulation, which I’ll leave to you since my challenge, getting the
file path returned from a field which only sends a file name, has been
solved and I NEED to get back to studying :-)

get file

if ($myfile) {
print “myfile = “.$myfiletext;



  1. Gregory Oct 16


    This is a nice solution!

    Classic Form-based (INPUT type=”File”) upload has one limitation: user can’t select multiple files.
    One of the sulutions to select at once and upload multiple files or all files within folder is Flash upload control. It works in all browsers and OSs and just needs Flash player on client side.
    See example here:

    Also this has rich progress bar.

  2. Serg Mar 17


    Take a look to one another flash upload control: EAFlashUpload

Leave a reply