Skip to content
Advertisement

FTP download folder with php

So I was wondering for I can download a intire folder from my FTP server, just by clicking on a link. When I have to download my .log files from my FTP server I do this:

First I create a link:

JavaScript

Then I call the downloader file:

JavaScript

By clicking the link, a browser download is started.

enter image description here

Is it possible to create a download file which downloads the whole folder, with all content in it?

Like download -> 'ftp://'.$ftp_user_name.':'.urlencode($ftp_user_pass).'@'.$ftp_server.'/'.$id.'/'.$folder

Advertisement

Answer

What i would do, is downloading all the files in the /tmp directory and then zip them all together into an archive. This file can then be streamed for as a response.

Make sure though that your tmp directory gets cleared, which normaly php does on its own after the request finished see here.

PHP ZipArchive

If you want to download all files within a single request (not within a folder).
This could work when using the ‘Content-Disposition’ value as a seperator between the file contents. I cannot confidently explain you what you would need for that. Maybe googling for ‘mulipart form request’ will give you a tutorial on that.

As for creating a direct folder as a response, i have never seen such a feature and don’t think it is possible.

In my opinion Zip is the best option here, as it should be supported widely enough, and keeps your folders intact, wich i think you want to keep.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement