PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 10, 2022

[FIXED] How can I deliver a PHP generated image with a specific filename?

 October 10, 2022     download, gd, jpeg, php     No comments   

Issue

So I have written a GD image 'modifier' we'll call it, and using the imagejpeg function, I output it to the browser. I'm curious if there is perhaps header information that I can pass that will instruct the browser to download the file with a name other than that of the PHP file that is handing the data back.

The scenario is that my PHP file, 'generate.php' for now, hands an image header out and outputs the image, but if I go to save the image, the default filename is 'generate.php'. I'd like to hand back a dynamically generated filename instead.

If code is a must here for some reason; I'll be glad to post it - but I feel it's not necessary in this case.


Solution

Send a Content-Disposition header.

To display the image:

header("Content-Disposition: Inline; filename=$filename");

To download the image:

header("Content-Disposition: Attachment; filename=$filename");


Answered By - AbraCadaver
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing