Jump to content

Recommended Posts

I have a script that allows an admin to upload an image to the server, the name is saved to the database associated with an event.

 

So, if the admin deletes an image that is associated with an event, is there any way to delete it in the db as well? I was thinking that it might work to have something like if $imagename = 0, show x.gif default image...but thinking about it, $imagename wouldn't be empty in the db...it just wont have an image to show.

 

Is there any way (besides not letting the admin delete images) to protect from broken image links?

Link to comment
https://forums.phpfreaks.com/topic/88235-default-image-if-image-has-been-deleted/
Share on other sites

mmm I was about to suggest file_exists, however, when would you update the database? Wouldn't it be better for it all to be checked when admin deleted the item? ((otherwise your also running file_exists on every single file, there or not, every time the page is requested!) Therefore which is the lesser of two evils?)

In theory, admins shouldn't be deleting files directly off the server, there should be a method for them to do so that will remove the file and the reference in the db.

 

Since that apparently isn't happening, you have two options...

 

Use file_exists whenever a page is called to check for the image, or have a cron that scans the directory for files and updates the database. 

 

The former is an extra call to the IO system each page load, the latter leaves time for non existent files to be called from your script (the time between the SA deleting the file and the cron running).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.