lilbadger25 Posted January 28, 2008 Share Posted January 28, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/88235-default-image-if-image-has-been-deleted/ Share on other sites More sharing options...
hitman6003 Posted January 28, 2008 Share Posted January 28, 2008 use the file_exists function to determine if it exists... if (file_exists($row['filename'])) { //display the file } else { //display default file } Quote Link to comment https://forums.phpfreaks.com/topic/88235-default-image-if-image-has-been-deleted/#findComment-451463 Share on other sites More sharing options...
tinker Posted January 28, 2008 Share Posted January 28, 2008 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?) Quote Link to comment https://forums.phpfreaks.com/topic/88235-default-image-if-image-has-been-deleted/#findComment-451466 Share on other sites More sharing options...
hitman6003 Posted January 28, 2008 Share Posted January 28, 2008 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). Quote Link to comment https://forums.phpfreaks.com/topic/88235-default-image-if-image-has-been-deleted/#findComment-451469 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.