The PHP script generates an HTML page for the client and a set of image files displayed by this page. After image files are displayed on the client, they should be deleted (on the server). Image files are images about 200x300 in size.

There are three ways to do this:

  1. Add a call to another onload HTML page handler in another frame of the cleanup script
  2. Put on the crowns a periodic garbage collection procedure
  3. In a PHP script, fork through a system or exec parallel process that will clean up garbage for a given pause. But somehow this is all ... Velma kucheryavo.

And is it possible to get a signal from Apache to complete the exchange with the client on this script and process it? Or specify Apache, that some files can be deleted after the completion of the exchange?

  • Why then physically create these pictures? Generate content-type: image / png directly with the script - toxxxa
  • @toxxxa What is the layout like in this case? Can a "frame" example, say, for two pictures? Excuse my possible denseness. - Mad Jackal
  • What is the specific task you face? - Naumov
  • @Naumov Pictures contain confidential information and are stored on the server in encrypted form. Before returning to the client, a decrypted copy is created and it should be deleted as soon as possible. It is clear that a crypto applet with decryption on the client would be an ideal solution, but ... these are completely different labor costs, let's say. - Mad Jackal

2 answers 2

Alternatively, you can make a page (let's call it image.php and it will be at the root) that will give such pictures and delete them immediately.

header('Content-Type: image/png'); $name = "/path/to/dir/".$_GET['name']; if(is_file($name)){ $im = imagecreatefrompng($name); if($im!==false){ imagepng($im); imagedestroy($im); unlink($name); } } 

In the very layout of src images indicate http://example.com/image.php?name=picture.png . This is an example, then you can make the name of the image numeric and transmit only the number of the image through $_GET without a format and check the correctness of the name.

    I did not do it myself, so basically the theory, let the elder comrades correct me:

    make a .htaccess redirect, so that instead of downloading images, the request is sent to the script:

     RewriteRule ^img/(.*\.jpg?)$ /image.php?file=$1 [L,R=301] 

    the script itself will produce the title and contents of the image:

     echo "Content-Type: image/png\n"; echo image_uncrypt($filename);