-2

So essentially I want to insert the Path into my Database, as a string, I am not interested in uploading it - I just want local users to browse to the file then submit the form and the path to the file is added as a string. So when I echo this out into a url, people on the network can click the link to download it from the network location.

$location = fopen($_FILES["location"]["tmp_name"], 'r');

I've tried the above but I guess the file needs to be uploaded for it to get the path.Form Button

Any ideas?

List of File Locations

MikeXero
  • 63
  • 1
  • 9
  • 3
    `insert the path into my database without uploading` doesn't make much sense - PHP will have no access to the file or path unless you upload it (most browsers even protect against the JS from knowing what is the path of the file in user's local machine). Maybe I'm not understanding right - could you explain what you are trying to achieve again? – Giedrius Aug 29 '17 at 16:36
  • I've added more context. What I can say though, is it will add the file name string (and file extension) to the database if I simply use input="file" and then insert the information into the database like that. – MikeXero Aug 29 '17 at 16:36
  • 1
    Anyone who had done their basic research on this should know by now that this is impossible, because as @Giedrius already mentioned, modern browsers hide the path from you - both on the client and the server side, for obvious privacy and security reasons. – CBroe Aug 29 '17 at 16:38
  • So if I understand correctly you have a bunch of files on your network and you want your PHP to read those and allow users to select one of them without uploading it? So they would select something like `X:/Files/file.txt`? – Giedrius Aug 29 '17 at 16:38
  • I want a user to upload where a file is stored, so then other users On the same network, can click on it (say F:/important-files/) and download it from an link (grabbed from my db) – MikeXero Aug 29 '17 at 16:42

1 Answers1

1

Unfortunately PHP will not help you with this as it requires you to actually upload the file.

Likewise, as was mentioned in the comment you are not able to get the local file path either from the form. This is a browser standard and is done for security purposes. You can read more about it here: https://stackoverflow.com/a/4176605/8518859

The only solution in your case is to provide a text input and ask the user to paste the network path to the file. Perhaps if you provide them simple instructions on how to get the network path it will make their task easier.

Mike S
  • 1,636
  • 7
  • 11