2011-05-18 48 views
0

在image.php,代码喜欢:问题与SRC保存图像文件

header("Content-Type:image/png"); 
$file = "img.png"; 
readfile($file); 

在其他文件,代码:

<img src="image.php"> 

,当我从浏览器中单击右键保存图像为,默认保存为image.php。我想将它保存为img.png,有什么想法?

回答

0

你也可以只是将此标头添加到您的PHP文件中:

header('Content-Disposition: attachment; filename="image.png"'); 
0

这可以通过使用URL重写来完成。

在你的.htaccess中,添加这样的事情(假设mod_rewrite的启用和你自己的Apache):

RewriteRule ^image.png$ /image.php [L] 

你的文件名HTML变化:

<img src="image.png" /> 
+0

该图像是由PHP文件生成的。 – wordpressquestion 2011-05-18 00:53:42

+0

正确。 URL重写映射'image.png'到'image.php'... image.php在这里被调用。 – 2011-05-18 01:04:47