开发者

I'm having URL File-access errors when using OpenDir. Why?

<?php

   $pathname = "http://myserver.com/projects/" . $_GET['project'] . "/"; 

   if ($handle = opendir($pathname)) {

        while (false !== ($file = readdir($handle))) {

          if ($file != "." && $file != ".." && (strpos($file, '.jpg',1))    ) {

            $photo= $pathname . $file;
            echo "<image src=\"" . $file . "\">";

          }
        }
        cl开发者_开发知识库osedir($handle);
    } 
 ?>

There is my code. All I'm trying to do is pass a URL parameter like "project=Flowers", and have PHP open a folder called /flowers/ and return ALL of the .jpg images inside it.

However, when I run my code, I get these errors:

**Warning: opendir() [function.opendir]: URL file-access is disabled in the server configuration in /nfs/c01/h03/mnt/73283/domains/myserver.com/test.php on line 3

Warning: opendir(http://myserver.com/projects/flowers/) [function.opendir]: failed to open dir: no suitable wrapper could be found in /nfs/c05/h02/mnt/76383/domains/kulthouse.com/html/staging/work.php on line 3**

Any ideas why this won't work??


Any ideas why this won't work??

Because you're using filesystem function to access a web URL

So, I'd make it

$_SERVER['DOCUMENT_ROOT'].'/projects/'.basename($_GET['project']).'/'

basename() is very important here, not letting anyone to browse any directory on your disk

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜