Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

temporary image file

Status
Not open for further replies.

georgeocrawford

Technical User
Aug 12, 2002
111
GB
Hi - wonder if someone can help?

I have written a script which takes a text input, processes it and displays the results using the
Code:
imagepng($im)
function. All works perfectly.

The only problem is that each time I run the script (a simple form which posts back into the same page) and the image is displayed, the browser shows its cached version of the image.

Clicking refresh in the browser loads the new image, but this is obviously not a very professional soultion!

I need some help with saving the png as a temporary file. I have tried this idea:

Code:
srand(time());
$random = (rand(0, 99999));
$path = "images/$random.png";
$open_file = fopen($path, "a+");
ImagePng($im, $path);

...which works great, and creates uniquely named images like 51386.png in the images folder.

However, to tidy things up I obviously want to delete the previous image before doing this, to save disk space. So:

Code:
$folder = opendir("images");
while ($file = readdir($folder)) {
     unlink($file);
     }

However, now I get this error:

Code:
Warning: unlink() failed (Operation not permitted)

This is, I guess, a permissions problem. I have tried adding
Code:
chmod($file, 0777)
into the
Code:
while
loop, but that fails too.

What am I doing wrong? Am I on the wrong track - Is there an easier way to save a GD output to a temporary file which can be used in a html page?

Thanks for any help!
 
Sorry - I am so stupid!

I should have put
Code:
unlink("images/$file")
- it was looking in the wrong directory!

Nevertheless, is this the best way to do what I am trying to do?

Any more professional soultions would be very interesting to look at.

George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top