By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,447 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

Delete temporary images after loading website

P: n/a
Hi there,

I am writing a PHP script which generates some charts using gnuplot.
This generates quite a large number of temporary image files. My
problem is that I do not know how to delete these images after they
have been loaded and are already displayed at the website.
Everything I have tried so far resulted in that the images were not
displayed at all.
I already tried something like:

sleep(10);
foreach ($images as $i) {
unlink($i);
}

also tried writing a shell script with the same functionality hoping
that starting the shell script in the background (using &) would
terminate the php script before the images were deleted.
Didn't work either.
Does anyone have an idea? I do not want to use a cron job or something
to clean the temporary directory.
Are there any php only solutions to this problem?

Cheers!
Andrea

Apr 30 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Apr 30, 10:24 am, Andrea Scharfe <schm...@gmail.comwrote:
I am writing a PHP script which generates some charts using gnuplot.
This generates quite a large number of temporary image files. My
problem is that I do not know how to delete these images after they
have been loaded and are already displayed at the website.
Everything I have tried so far resulted in that the images were not
displayed at all.
Dear Andrea,

why don't you delete the files the next time you call the script
before you create new temporary files?

Good luck
Martin

------------------------------------------------
online accounting on bash bases
Online Einnahmen-Ausgaben-Rechnung
http://www.ea-geier.at
------------------------------------------------
m2m server software gmbh
http://www.m2m.at

Apr 30 '07 #2

P: n/a
On 30 Apr., 10:53, Martin Mandl - m2m tech support
<martin.ma...@gmail.comwrote:
On Apr 30, 10:24 am, Andrea Scharfe <schm...@gmail.comwrote:
I am writing a PHP script which generates some charts using gnuplot.
This generates quite a large number of temporary image files. My
problem is that I do not know how to delete these images after they
have been loaded and are already displayed at the website.
Everything I have tried so far resulted in that the images were not
displayed at all.

Dear Andrea,

why don't you delete the files the next time you call the script
before you create new temporary files?

Good luck
Martin

------------------------------------------------
online accounting on bash bases
Online Einnahmen-Ausgaben-Rechnunghttp://www.ea-geier.at
------------------------------------------------
m2m server software gmbhhttp://www.m2m.at
Hi Martin,

thanks for your reply. The problem is, that the script is used for a
website which might be accessed by more than one person at the same
time. So it might happen that while one person is waiting for the
charts to be displayed, the next user accesses the website and deletes
the files the other one is waiting for.
Maybe I could include a check for timestamps and delete all files that
are older than 5 minutes or something...

Thank you!

Andrea

Apr 30 '07 #3

P: n/a
Andrea Scharfe wrote:
also tried writing a shell script with the same functionality hoping
that starting the shell script in the background (using &) would
terminate the php script before the images were deleted.
Didn't work either.
Does anyone have an idea? I do not want to use a cron job or something
to clean the temporary directory.
Are there any php only solutions to this problem?

Cheers!
Andrea
How about having the PHP script accept parameters on the query string,
generate to your graph in an inline IMG tag eg.

<img src="gengraph?p1=100&p2=200 ..." />

PHP script generates img, returns it to the browser, then deletes the files.

Is the problem that you don't know what the temporary files are called
or that they always have same name?
Apr 30 '07 #4

P: n/a
I do the image generation with an external programme (gnuplot), so the
images are not generated by PHP directly.
I now found the following solution, which seems to work quite well:

/* remove older images in folder temp */

$command = "ls ".$_CONFIG["tempdir"];
exec($command, $output, $retval);
$time = time();
foreach ($output as $file) {
if (($time-filemtime($_CONFIG["tempdir"]."/".$file))>300) {
unlink($_CONFIG["tempdir"]."/".$file);
}
}

Thanks for your comments!
Andrea

Apr 30 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.