Force download from ftp using curl...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
astroboy44
Forum Newbie
Posts: 1
Joined: Tue Jan 11, 2011 6:00 am

Force download from ftp using curl...

Post by astroboy44 »

Hi guys,I am trying to force download files from ftp server to my local machine using the following code.

Code: Select all

<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"" . basename($filename) . "\"");
header("Content-Transfer-Encoding: binary");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'ftp://username:password@localhost/'.$path.'/'.$filename);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec ($ch);
curl_close($ch);
?>
The above code works perfectly for text files and pdf but when I try to download image or doc or any other files types ,the file gets corrupted.I even changed the content type to appropriate file types but no luck.I'm testing on my local machine with wamp server and filezilla server.
I'd be glad if someone could help me.
Thank you.
Post Reply