Page 1 of 1

Force download from ftp using curl...

Posted: Tue Jan 11, 2011 6:18 am
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.