0

For a custom WordPress plugin, I'm trying to allow my users to select a folder and use it as the file download path. Example: If the user selects the folder "C://Users/Kahiego/Desktop/img", may it be empty or not, when they'll try to download files from the plugin, everything will get downloaded in there.

So far all I can achieve right now is allowing to select a folder:

<form action="" method="post" enctype="multipart/form-data"> 
   <input type="file" id="ctrl" webkitdirectory directory multiple/>
   <input type="submit" value="Upload Image"> 
</form> 

(but it will only count as a multiple file select). I checked on various posts already but none can tell me how to achieve this (with some saying they don't see how this could be useful).

Any idea?

Thanks in advance.

Edit: What I mean by this: I want the admin to be able to pick a folder. I just want to retrieve the path, and use it somewhere else; not necessarily right afterward.

After retrieving the uploaded file, I currently use:

move_uploaded_file($_FILES["file"]["tmp_name"], "../../../img/" . $_FILES["file"]["name"]);

to store the files. I just wanted to allow to store the path in a variable through an input and use it afterwards in this case.

I'm not talking about browsing user's folders, but allowing the server to pick the location where files are downloaded, on the server itself, without writing the path, just by letting the admin selecting it by browsing files.

The flagged duplicated post does not answer or not totally answer what I'm looking for, since it's either selecting a folder - with every files in there - or not allowing to select a folder which is empty. Would be perfect to reproduce the functionality of those "select a directory" functions when you first install a software.

I hope I clarified enough, I'm really bad at explaining things.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Kahiego
  • 11
  • 1
  • https://stackoverflow.com/questions/2809688/directory-chooser-in-html-page – Zeljka Nov 26 '19 at 15:43
  • 1
    Your app has nothing to do with where the browser store downloads. That's between the user and the browser. Your app can't affect that in any way, which is a good thing. If sites could decide that, we would have files scattered all over our file systems, and it would be a security issue as well. – M. Eriksson Nov 26 '19 at 15:47
  • @MagnusEriksson Who I called "user" is the server admin of the wordpress website, that's supposed to be a plugin allowing registered writters to send file to the admin, and the plugin will download and store files in the dedicated folder. I just wanted to allow the admin to just pick the folder without the pain of writing the path himself. – Kahiego Nov 26 '19 at 15:54
  • Possible duplicate of [Directory Chooser in HTML page](https://stackoverflow.com/questions/2809688/directory-chooser-in-html-page) – thirdDeveloper Nov 26 '19 at 16:02
  • To be honest, that explanation didn't really clarify much. No matter who's downloading it, your site can't decide where on the users computer the files will be downloaded. If that's not what you're trying to do, then please edit the question and add a proper example of the expected flow (from start to finish) and explain where you're stuck. – M. Eriksson Nov 26 '19 at 16:26

0 Answers0