Dynamic Image Saving

Discussion in 'PHP' started by cesarcesar, Aug 10, 2007.

  1. #1
    I have a page thats sole function is to generate a dynamic image. When the image is loaded on screen, the only code within the source code body is
    <img alt="my alt tag" src="http://www.my-site.com/get.php?image_id=1" />
    HTML:
    When i right click on the image and try a "save as.." the suggested file name is *get.php.jpg*. So good so far.

    What i want to do is load this page in the buffer or cache, then rename and save the generated image to a designated folder on my server, instead of displaying it. Once i save the image, i will just header() to another page for display. Is there a way to do what i describe?
     
    cesarcesar, Aug 10, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    If I understand you right, you want to use a header() redirect in your get.php file? And redirect an embedded image? That's not possible.

    Can I may ask why you want to do that? If you want to change the file name when you right click and "save as", you can do that with a header command too.

    
    header('Content-Disposition: inline; filename="your-file.jpg"');
    
    PHP:
     
    nico_swd, Aug 10, 2007 IP
  3. daman371

    daman371 Peon

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well first of all it isn't suggested to use a header to redirect a page. Use a
    
    <meta http-equiv="refresh" content="2;url=http://somesite.com">
    
    Code (markup):
    2 is the delay in seconds. From what I get you want to save the image to the server and it is created on the page so there is an image resource. To save it somewhere on the server make sure the directory is writeable and call
    
    imagejpeg($resource, "directory/");
    
    Code (markup):
     
    daman371, Aug 11, 2007 IP