1

I have a simple HTML form that allows a user to select a file.

What's supposed to happen next is the function called loops through most the files in the source directory(based on file type) to input a bunch of production statistics into a local DB.

The only problem is I can't get the absolute path from for example the C:My Docs. I can get the temporary path that gets assigned to the one file but not the original.

So is there anyway in the page sending the file to get the path and send the string? Or get the absolute path in the function that the HTML form calls?

Thanks, bmckie

Brad Mc
  • 151
  • 1
  • 13
  • 1
    You cannot get users path of the file! – Glavić Nov 13 '13 at 18:10
  • 1
    If you are referring to the local filepath, that is not possible for security purposes. http://stackoverflow.com/questions/15201071/how-to-get-full-path-of-selected-file-on-change-of-input-type-file-using-jav – showdev Nov 13 '13 at 18:10

2 Answers2

1

When a file is posted to PHP, it is always initially saved in the temporary path. The PHP script that is receiving the post needs to use that temporary path and the move_uploaded_file() function to actually save it to a more permanent, desired location.

<?php
move_uploaded_file($_FILES["picture"]["tmp_name"], "/path/to/directory/filename.ext);

The move_uploaded_file function takes two parameters. The first is the current location of the file. You can inspect the $_FILES superglobal variable to find this and other things including the original filename. The second parameter is the path and filename you want to save it as on your local (server) system. You can use whatever naming convention you want. However, the original filename can also be found from the $_FILES superglobal variable.

Sajan Parikh
  • 4,668
  • 3
  • 25
  • 28
0

For security reasons, the browser is not permitted to store/send the path of the file on the user's computer.

These SO posts have particularly helpful information:

How to get the file path from HTML input form in Firefox 3

How to get the full path of the file from a file input

More Links:

http://kb.mozillazine.org/Links_to_local_pages_do_not_work

getting file path through browse button

How to resolve the C:\fakepath?

http://en.wikipedia.org/wiki/File_URI_scheme

Community
  • 1
  • 1
cssyphus
  • 37,875
  • 18
  • 96
  • 111