php - File does not exist though the path seems right -


i can't figure out why file_exists() don't find file though path seem right.

here script :

if($_post['delete-avatar'] == 'on') {   $q = execute_query("select avatar gj_customers id_customer = '$_get[id]'");   $customer = $q->fetch_assoc();   $img_path = $_server['document_root'] . website_root . $customer['avatar'];   var_dump($img_path);    if(!empty($customer['avatar'])  && file_exists($img_path)){     unlink($img_path);   } } 

i'm on mamp, website in htdocs/gamejutsu/www/ , website_root contains '/gamejutsu/www/' , avatars in img/avatars/ .

var_dump on $img_path returns me : /applications/mamp/htdocs/gamejutsu/www/img/avatars/sonik_avatar.jpg.

if go on localhost:8888/gamejutsu/www/img/avatars/sonik_avatar.jpg image displayed.

i never enter in if bloc. if remove file_exists test have warning : unlink(/applications/mamp/htdocs/gamejutsu/www/img/avatars/sonik_avatar.jpg): no such file or directory in /applications/mamp/htdocs/gamejutsu/www/admin/members.php on line 67

i'm pretty sure i'm missing seems ok me , use same method somewhere else on website without problem.

thank help.

it complicated debug application without access can try return realpath();

var_dump(realpath($img_path)) 

if returns null file doesn't exists or application haven't acces it.

try open console , command:

cd /applications/mamp/htdocs/gamejutsu/www/img/avatars/ 

if have error have bad path , must manualy check (easiest console) if can cd in directory. please add here ls of directory check permissions:

ls -la /applications/mamp/htdocs/gamejutsu/www/img/avatars/ 

and if try change console user webserver user (usually www-data) , try acces file

sudo su su www-data cat /applications/mamp/htdocs/gamejutsu/www/img/avatars/sonik_avatar.jpg 

if can acces file (it binary data) permissions ok, in other case check if have right permission file , if owner , group of file.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -