I'm trying to delete a picture (.jpg) from server after the first time showed. But the file is deleted (unlink();) before showed. I've already tried with sleep() but this only delay the loading and after all the file is deleted before showed.
You could use mod_rewrite to redirect jpg requests to a script that loads the image into memory, deletes the file, then serves up the image. IMO, this is the simplest and easiest solution. Unsafe example below...
Example .htaccess file:
# Turn on URL rewriting
RewriteEngine On
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
index.php
<?php
$image_file = $_SERVER['PATH_INFO'];
// clean data, strip current/parent directory to block transversal, etc...
if (file_exists('images/' . $image_file))
{
$image_data = file_get_contents('images/' . $image_file);
// determine image mimetype using phps mimetype functions
unlink('images/' . $image_file);
header('Content-Type: image/jpeg');
echo $image_data;
}
Best I can do with the vagueness, I'm afraid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With