unlink() not working while I try to remove an image PHP -
i trying remove image directory using unlink()
function.
if (file_exists($oldpicture)) { unlink($oldpicture); echo 'deleted old image'; } else { echo 'image file not exist'; }
the value of $oldpicture
../images/50/56/picture.jpg
.
the follow block of code runs without errors when check directory image still there.
am doing wrong here?
thanks
"@fred-ii- yeah right, getting denied permission...any idea how can fix this? p.s. error reporting amazing, me that! – bigrabbit"
use chmod on file before unlinking it:
if (file_exists($oldpicture)) { // last resort setting // chmod($oldpicture, 0777); chmod($oldpicture, 0644); unlink($oldpicture); echo 'deleted old image'; } else { echo 'image file not exist'; }
a last resort setting using 0777
in commented code.
"how use var_dump() check folder/file permissions?"
- it's not check permissions check being passed through variable.
i.e.: var_dump($oldpicture);
if (file_exists($oldpicture)) { var_dump($oldpicture); // last resort setting // chmod($oldpicture, 0777); chmod($oldpicture, 0644); unlink($oldpicture); echo 'deleted old image'; } else { echo 'image file not exist'; }
add error reporting top of file(s) find errors.
<?php error_reporting(e_all); ini_set('display_errors', 1); // rest of code
sidenote: error reporting should done in staging, , never production.
Comments
Post a Comment