Jump to content

[SOLVED] saving an image


acidglitter

Recommended Posts

I have this code to make an image (this is only the end of it..)

header('Content-type: image/png');
imagepng($image_resized);
imageDestroy($image_resized);

 

But how can I use PHP to save this image to a folder on my website?

 

header('Content-type: image/png');
imagepng($image_resized); // sends the image to the browser
imagepng($image_resized, "resized_image.png"); // saves the image to the same folder as the script. (change the name accordingly)
imagedestroy($image_resized);

 

Hope that helps :)

 

Sam

Link to comment
Share on other sites

I tried that but it didn't save it :(

 

That's odd, because it should do.  Put

 

<?php

error_reporting(E_ALL);

ini_set('display_errors', true);


?>

 

at the top of your code. Tell us if it returns any errors?

 

EDIT: Are you running this script from the site you are wishing to save the image on?

 

Sam

Link to comment
Share on other sites

oh the codes right but i didn't change the permissions for the folder. so its working now :)

 

but how can i save it to a different folder?

 

imagepng($image_resized, "./images/resized_image.png");

 

Along those lines with help. just change that last part to where you want to image to go to. (as long as you have write permissions for that folder it will go to it).

 

Hope that helps?

 

Sam

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.