I use following code to delete old image from ftp...
unlink(getcwd() . '/images/' . $row['pic']);
But it throws errors in case there is not image, so i have tried using file_exists() but that didn't work too, so how can i check if there is an image before trying to delete. thanks.
if(file_exists(getcwd() . '/images/pics/' . $row['pic']))
{
unlink(getcwd() . '/images/pics/' . $row['pic']);
}
often hosters use different user for ftp and apache… could it be, that you don't have chmodded your images, so the www-user can't delete them?
edit:
maybe is_writable is the better solution for you:
if(is_writable(dirname(__FILE__) . '/images/pics/' . $row['pic'])){
unlink(dirname(__FILE__) . '/images/pics/' . $row['pic']);
}
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