0

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?

2 Answers 2

1

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

header('Content-Disposition: attachment; filename="image.png"');
Sign up to request clarification or add additional context in comments.

Comments

1

This could be accomplished through the use of URL rewriting.

In your .htaccess, add something like this (assuming mod_rewrite is enabled and you're on Apache):

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

Your HTML changes with the file name to:

<img src="image.png" />

2 Comments

The image is generated by PHP file.
Correct. The URL rewrite maps 'image.png' to 'image.php'... image.php is getting called here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.