当我使用此代码从我的网站下载图像时,它向我显示图像已损坏,但相同的代码在其他域上正常工作。
Error when I am downloading the image
为什么此代码无法在我的域上运行?
此代码定义了我们如何在浏览器中下载图像:
<?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");
?>
答案 0 :(得分:0)
你可以尝试这段代码,它会起作用:
<?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");
?>