Search code examples
phpimagesrc

Problem with save image file in src


In image.php, the code likes:

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

In other file, the code is:

<img src="image.php">

when I right-click from browser to Save Image As, it defaults to save as image.php. I would like to save it as img.png, any idea?


Solution

  • You could also just add this header to your PHP file:

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