Welcome Guest, Not a member yet? Register   Sign In
PHP force download png
#1

Hi;
Hi for some reason I cannot use Codeigniters force_download. I thought I learn first how to do it without CI so I can figure it out.

How can I force download this png file? This one downloads a file but the file can not be opened since it's damaged!

PHP Code:
$image='http://clickbank.wpengine.netdna-cdn.com/wp-content/uploads/2014/12/andrea-image-compressed.png';
 if(@
getimagesize($image))
 {
 
header('Content-type: image/png');
 
header('Content-Disposition: attachment; filename=my_file.png');
 
readfile(file_get_contents($image));
 } 

I also got this from the manual, but same thing, broken file:
PHP Code:
$image='http://clickbank.wpengine.netdna-cdn.com/wp-content/uploads/2014/12/andrea-image-compressed.png';
header('Content-Description: File Transfer');
 
   header('Content-Type: application/octet-stream');
 
   header('Content-Disposition: attachment; filename='.basename($image));
 
   header('Expires: 0');
 
   header('Cache-Control: must-revalidate');
 
   header('Pragma: public');
 
   header('Content-Length: ' filesize($image));
 
   readfile($image); 
Reply
#2

You can achieve that by using CI Download helper.
$this->load->helper('download');
$content = file_get_contents("http://ointuit.ru/wp-content/uploads/2014/09/PHP5.jpg"); // Read the file's contents
$file_name = 'myfile.jpg';

force_download($file_name, $content);
Reply




Theme © iAndrew 2016 - Forum software by © MyBB