unemployment Posted September 12, 2011 Share Posted September 12, 2011 After a user on my site deletes their account I want their profile picture to be deleted from my images folder. I was testing the unlink function on my index.php file and it is failing. Here is the error: Warning: unlink(/assets/img/avatars/users/jasongordon.png): No such file or directory in /home/www-data/big.com/index.php on line 86 My code was just: unlink('/assets/img/avatars/users/jasongordon.png'); I'm not sure why this fails because my file does exist. Quote Link to comment https://forums.phpfreaks.com/topic/246981-unlink-file-in-img-directory/ Share on other sites More sharing options...
AbraCadaver Posted September 12, 2011 Share Posted September 12, 2011 What is the full path to the file? /assets/img/avatars/users/jasongordon.png or /home/www-data/big.com/assets/img/avatars/users/jasongordon.png Quote Link to comment https://forums.phpfreaks.com/topic/246981-unlink-file-in-img-directory/#findComment-1268433 Share on other sites More sharing options...
unemployment Posted September 12, 2011 Author Share Posted September 12, 2011 What is the full path to the file? /assets/img/avatars/users/jasongordon.png or /home/www-data/big.com/assets/img/avatars/users/jasongordon.png On my server it's /home/www-data/big.com/assets/img/avatars/users/jasongordon.png Quote Link to comment https://forums.phpfreaks.com/topic/246981-unlink-file-in-img-directory/#findComment-1268434 Share on other sites More sharing options...
JKG Posted September 12, 2011 Share Posted September 12, 2011 you need to use unlink('/home/www-data/big.com/assets/img/avatars/users/jasongordon.png'); then. php's root directory is deeper than the html root directory. Quote Link to comment https://forums.phpfreaks.com/topic/246981-unlink-file-in-img-directory/#findComment-1268441 Share on other sites More sharing options...
AbraCadaver Posted September 12, 2011 Share Posted September 12, 2011 Or use: unlink('./assets/img/avatars/users/jasongordon.png'); or unlink('assets/img/avatars/users/jasongordon.png'); Quote Link to comment https://forums.phpfreaks.com/topic/246981-unlink-file-in-img-directory/#findComment-1268445 Share on other sites More sharing options...
unemployment Posted September 12, 2011 Author Share Posted September 12, 2011 I decide to go with unlink("{$GLOBALS['path']}/img/avatars/companies/${cid}.png"); Quote Link to comment https://forums.phpfreaks.com/topic/246981-unlink-file-in-img-directory/#findComment-1268453 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.