1

I'm trying to find a way to select a folder in PHP. I've checked all the similar questions and they all seem to relate to uploading files, scanning directories and such.

Basically I want a form from a page on my PHP intranet site to have a 'Select folder' button, which then opens the browse window similar to uploading a file however I only want to save the folder location.

So I want my users to be able to browse for a folder, click it and it will just fill the text box with e.g. U:/Projects/Project1

Because all the folders have consistent folder structure, I can use this folder location to generate links by just appending e.g. '/Files/Form.doc' to create 'U:/Projects/Project1/Files/Form.doc'

With my limited knowledge, the only solution I can think of would be to have the users select any file from the directory required e.g. 'U:/Projects/Project1/Test.txt' as a html input with no upload attached and save it as a string, then explode the string as an array by the slashes and remove anything beyond the last slash..

If anyone can think of a solution to this, or knows a library which has this capability it would be greatly appreciated.


EDIT : I have a perfectly working folder path selector that only works in IE - making use of an ActiveX control. My users mostly use chrome so now I am investigating avenues such as the 'ActiveX for Chrome' extension while also looking at alternatives such as VB scripts.

Matadeleo
  • 504
  • 8
  • 18
  • do you have read http://stackoverflow.com/questions/12942436/how-to-get-folder-directory-from-html-input-type-file-or-any-other-way or http://stackoverflow.com/questions/2809688/directory-chooser-in-html-page – Eugen Jan 06 '15 at 10:13
  • @Eugen Yes, i read both of these questions. The first relates to folder uploads so isn't helpful for my question. The second question has an answer regarding directory uploads which isn't what I want to do. KMån's answer in the second question is intrigueing but when I tried his solutions, they didn't appear to be working. – Matadeleo Jan 06 '15 at 11:39

1 Answers1

0

You are talking about client side input. That has nothing to do with PHP, as that is a server side script.

Selecting a folder is not possible in javascript, because of security reasons. Javascript can only return selected file information such as filename, filesize, filetype, but not where the file is situated on the filesystem.

The only solution I ever found, was to select a folder with an activeX application: http://www.tek-tips.com/faqs.cfm?fid=5201

Au.Merci
  • 51
  • 3
  • I included PHP as it would be used in my potential solution making use of the explode() function to strip the file name out of the directory – Matadeleo Jan 06 '15 at 11:35
  • Did you ever get that solution working? I tried that earlier today, I put the first bit of code in an index.html, the second in folderDialog.html yet recieve the error: **Uncaught ReferenceError: showModalDialog is not defined** – Matadeleo Jan 06 '15 at 12:01
  • I also didn't get it working, but also didn't invest a lot of time to search why it didn't work. I had the same question as you a while back, but my conclusion was that it was only possible by activeX, which is not suitable for me. Did you already looked into this? http://msdn.microsoft.com/en-us/library/windows/desktop/bb774065%28v=vs.85%29.aspx – Au.Merci Jan 10 '15 at 22:38
  • Unfortunately i'm not familiar with those languages and have no idea how I could implement that code. I've got a solution working perfectly with ActiveX, so works great with IE. Trying to get a chrome activex addon working as IE/Chrome are the only browsers we use. – Matadeleo Jan 12 '15 at 16:01