Hi guys,I am trying to force download files from ftp server to my local machine using the following code.
<?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.e the size of the downloaded file and the file on the server is same but when I open them using appropriate application , it says file 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.