0

I have written a script in PHP that connects to my FTP server and downloads the latest backup of all the websites I have created.

I have written this script in PHP (using ftp_get and all those lovely functions!), but I have also created a nice looking dashboard in HTML, which uses AJAX to not only execute the PHP code but to output all the "echo"'s into a textarea so I know which ones were successfully downloaded and which ones failed.

My problem is that I am not the only employee, there are quite a few of us who could execute this script, so on the dashboard I want there to be a way of choosing where these backsup are saved without having to edit a hardcoded destination in the PHP. At the moment, it's hardcoded to save to my desktop, but if someone else were to use it on their computer, it won't work.

I have tried searching for this, but no one has asked exactly the question I needed answering.

If the answers could be using HTML, JavaScript/jQuery or PHP, that would be handy.

Thank you in advance.

------------EDIT------------

Not sure people are understanding my problem, so I will try and explain it differently :)

I have a backup tool that will connect to an FTP server, go through each project folder and download the latest backup of that site. In total, there are at least 20 files to be downloaded.

Multiple people will be using this tool, depending who is around to backup the files.

Bob might want to save it directly to his desktop: C:/Users/Bob/Desktop.

Barbara might want to save it in C:/Users/Barbara/Backup Folder/2017/

Jimmy wants to save it in C:/Users/Jimmy/Projects/Project_name/Backup-01-01-2017

And I might want to save it onto an external HDD.

I want the tool to have a function that will allow the user to specify a location on their HDD where these files will all be saved.

I hope this is clearer.

Many thanks.

Obelisk
  • 39
  • 5
  • If you have an identifier per user you can use that information to send it back to pho and connect to an FTP and use a folder per user. – ProgrammerV5 Apr 06 '17 at 14:27
  • 1
    maybe this help you: http://stackoverflow.com/questions/3278553/php-download-any-file-from-ftp-server-to-harddrive?answertab=oldest#tab-top – Mubashar Iqbal Apr 06 '17 at 14:37
  • How about making your destination path a variable in the backend; and then posting the path each time you execute the script (using a simple form post or something) ? Though that's very straightforward, I didn't quite get the complication here. – Echoes Apr 06 '17 at 14:39
  • @Echoes I just want to make it as simple as possible. Yes, I could use a form but that would mean we would have to memorise our Desktop paths, where as simply choosing where to save it, much like you would when downloading a file online, would be easier. – Obelisk Apr 06 '17 at 15:24
  • @ChrisK Oh well in that case you can completely skip defining the destination path option, all you can do is- access the file you need to download and then use php header to auto-prompt the download window, something like `header('Content-Disposition: attachment; filename="'. $YourFile .'"');` – Echoes Apr 06 '17 at 15:32
  • 1
    This might be helpful: http://stackoverflow.com/questions/2877873/download-prompt-for-ftp-get – Echoes Apr 06 '17 at 15:38
  • @Echoes Would that work with selecting a directory in which to download a long list of files? – Obelisk Apr 06 '17 at 15:50
  • Obelisk, if you have multiple files, you might want to consider [zipping](http://php.net/manual/en/book.zip.php) them with PHP first, then offer that zip file for download. See [this question](https://stackoverflow.com/questions/12225964/create-a-zip-file-and-download-it) or [that question](https://stackoverflow.com/questions/1061710/php-zip-files-on-the-fly) for example. – domsson Jul 10 '17 at 14:22
  • @domdom Thank you all for your answers. They have been constructive and helpful. Now I am facing a new potential issue. Someone has expressed interest in moving it straight to another FTP server. How feasible is this? Move the now zipped file from one FTP server straight to another without having to download it to your own machine first? – Obelisk Jul 11 '17 at 13:13
  • Yes. In fact, I think that makes a lot more sense than the *download* option. And it is totally feasible using [`ftp_put()`](http://php.net/manual/en/function.ftp-put.php). Probably easier too. You could then even omit the zipping. – domsson Jul 11 '17 at 13:16

0 Answers0