Download image header code not working on my domain

71 views Asked by At

When I am downloading the image from my website using this code it is showing me that image is damaged, but same code is working fine on other domains.

Error when I am downloading the image

Why is this code not working on my domain?

This code defines how we can download the images in the browser:

<?php
    header( 'Pragma: public' );
    header( 'Expires: 0' );
    header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
    header( 'Cache-Control: private', false );
    header( 'Content-Description:File Transfer' );
    header($_SERVER['SERVER_PROTOCOL'].' 200 OK');
    header( 'Content-Type: image/png');
    header( 'Content-Disposition: attachment; filename="header.jpg";' );
    header( 'Content-Transfer-Encoding: binary' );
    header( 'Content-Length: ' . filesize("images/header.jpg") );
    readfile("http://iqet.com/images/header.jpg");
?>
1

There are 1 answers

0
Bhumi Shah On

You can try this code, it will work:

<?php
    header( 'Pragma: public' ); 
    header( 'Expires: 0' );
    header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
    header( 'Cache-Control: private', false );
    header( 'Content-Description:File Transfer' );
    header( 'Content-Type: image/jpeg');
    header('Content-Disposition: attachment; filename='.basename('http://iqet.com/images/header.jpg'));
    readfile("http://iqet.com/images/header.jpg");
?>