if file exists php -


i use following code delete old image ftp...

unlink(getcwd() . '/images/' . $row['pic']); 

but throws errors in case there not image, have tried using file_exists() didn't work too, how can check if there image before trying delete. thanks.

if(file_exists(getcwd() . '/images/pics/' . $row['pic']))  {     unlink(getcwd() . '/images/pics/' . $row['pic']); } 

often hosters use different user ftp , apache… be, don't have chmodded images, www-user can't delete them?

edit:

maybe is_writable better solution you:

if(is_writable(dirname(__file__) . '/images/pics/' . $row['pic'])){   unlink(dirname(__file__) . '/images/pics/' . $row['pic']);  } 

Comments