Delete temporary images after loading website

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrea Scharfe

    Delete temporary images after loading website

    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

  • Martin Mandl - m2m tech support

    #2
    Re: Delete temporary images after loading website

    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

    ------------------------------------------------
    m2m server software gmbh


    Comment

    • Andrea Scharfe

      #3
      Re: Delete temporary images after loading website

      On 30 Apr., 10:53, Martin Mandl - m2m tech support
      <martin.ma...@g mail.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

      Comment

      • Tyno Gendo

        #4
        Re: Delete temporary images after loading website

        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?p 1=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?

        Comment

        • Andrea Scharfe

          #5
          Re: Delete temporary images after loading website

          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($_CON FIG["tempdir"]."/".$file))>3 00) {
          unlink($_CONFIG["tempdir"]."/".$file);
          }
          }

          Thanks for your comments!
          Andrea

          Comment

          Working...