2012-08-09 221 views
5

我遇到了scandir()问题。我试图在我的云中的子域下的页面上显示我的snaps目录中的文件。scandir无法打开目录

这是我使用的PHP。

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

并且这是错误。

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 

我不知道该怎么办。

回答

2

假设错误,你扣目录必须有

/home/u703778423/public_html/cloud/snaps 

的绝对路径确保这是对目录中的正确位置,以及Web服务器有权限访问它。

+0

你怎么知道的?没有提到,'。/ snaps'应该在哪里,但只有'。/ snaps'丢失。 – KingCrunch 2012-08-09 14:35:50

+0

@KingCrunch:因为脚本的位置是在错误信息中指定的,而scandir中的路径是'。/ snaps'。 – 2012-08-09 14:36:57

+0

捕捉直接在public_html中。 – 2012-08-09 14:37:12

7

您可能会假设,当前工作目录是在scandir()脚本旁边写入的,而在许多情况下则不是。

scandir(__DIR__ . '/snaps'); 
0

首先你试图显示一些文件,不会呈现为图像...前。 (。压缩)。

另外你是否确定你没有试图显示前两个索引值“。”和“..”?我在想这段代码可能不是问题...

相关问题