How can PHP be used to deliver images to users and then automatically delete them after they have been displayed?
To deliver images to users and automatically delete them after they have been displayed, you can use PHP to generate a unique URL for each image request. Once the image is requested and displayed, you can use a cron job or a background process to delete the image file after a certain period of time.
<?php
// Generate a unique image URL
$imageName = "image.jpg";
$imagePath = "path/to/images/" . $imageName;
$uniqueUrl = "http://example.com/image.php?name=" . $imageName;
// Output the image
header('Content-Type: image/jpeg');
readfile($imagePath);
// Delete the image after display
unlink($imagePath);
?>
Related Questions
- How can PHP and MySQL be integrated to create a seamless process for populating tables with form data?
- How can Dependency Injection be utilized in PHP to streamline the process of debugging and error handling in classes?
- How can PHP be used to retrieve server time rather than user time on a webpage?