Question : [PHP] Initiate an FTP Download [Will give A++]

Hello,
Our business has an FTP for users to download updated versions of software. Thing is though that we don't want them to have the ability to download other versions than the ones we specify.

What I have done though is created a user database where they can login and we have a list of files that they ARE allowed to download.
What we want though is the ability for the user to click a link and they are connected to the FTP and a download is initiated for that specific file.

Our FTP server has usernames & passwords.

Does anyone have any suggestions or examples of how this can be done?
Thank you in advance.

Answer : [PHP] Initiate an FTP Download [Will give A++]

if the ftp username and password it's specific to each user then you can make the links like this

ftp://user:[email protected]er.com/fileToDownload.zip

if the ftp username and password it's yours and you do not need the user to know it then you can make a link to a php file that will stream the file to the user so the script will connect to the ftp and read the file and sendit to the user

depending on the size of the file this can be done in many ways

for a small file <20 mb you can do somenthing like this

1:
2:
3:
4:
5:
6:
7:
8:
$url=urlencode('ftp://user:[email protected]/fileToDownload.zip');
$filename='test.zip';
$zip=file_get_contents($url);
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=$filename"); 
header("Content-Description: PHP5 Generated Data" );
header("Content-Length: ".strlen($zip));
print $zip;
Random Solutions  
 
programming4us programming4us