Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scandir fail to open directory

Tags:

php

I am having trouble with scandir(). I am trying to display the files in my snaps-directory on a page under the subdomain in my cloud.

This is the PHP I used.

$files = scandir('./snaps');
print_r($files);

and this is the error.

Warning: scandir(./snaps) [function.scandir]: failed to open dir: No such file or directory in /home/u703778423/public_html/cloud/index.php on line 39

Warning: scandir() [function.scandir]: (errno 2): No such file or directory in /home/u703778423/public_html/cloud/index.php on line 39

I have no idea what else to do.

like image 261
Cody Lee Kaczynski Avatar asked Aug 09 '12 14:08

Cody Lee Kaczynski


2 Answers

You probably assume, that the current work directory is next to the script scandir() is written in, which (in many cases) isn't.

scandir(__DIR__ . '/snaps');
like image 57
KingCrunch Avatar answered Nov 09 '22 03:11

KingCrunch


Given that error, your snaps directory would have to have the absolute path of

/home/u703778423/public_html/cloud/snaps

Make sure that this is the correct location for the directory, and that the webserver has the rights to access it.

like image 25
Marc B Avatar answered Nov 09 '22 01:11

Marc B