tags:

views:

68

answers:

1

How would I go about catching a request for images that doesn't exist and create them as needed so as not to return a 404? These would then be stored on the server until no longer needed and deleted. The code would preferably be in PHP. Deletion will most likely occur in a cron job.

The images would be requested in batches of 10 or so at a time with names such as 084a007b0138024f0a.jpg.

+2  A: 

Edit your htaccess, so in that folder requests for any image is redirected to a PHP script.

Then, in your script, create the image (http://php.net/image/) and simply echo it.

pestaa
Thanks, I'll give that a try.
graham.reeds
You're welcome, thanks for the plus!
pestaa
No problem. I was wondering about performance penalties. Could it handle a scenario where it first looked to see if the file existed and if not accessed the script? Or would you have to handle that in the script?
graham.reeds
that would call PHP *every* time you request that image.
vartec
Not necessarily. If htaccess configured correctly, PHP is only called when image is non-existent.
pestaa
What's wrong with calling PHP every time? You can then contain all of the logic for managing creation and deletion of the images in a single PHP application.
@pestaa if you're only echoing it, it'll never exist
vartec
@vartec, "creating the image" means saving it at the same time in this context.@mozboz: If the site has gained a rather big popularity, calling PHP for every image can be a resource hog.
pestaa