开发者

Php scandir() problems

I was wondering, my Scandir() function works on a php $_GET variable, so the variable returns the folder, but I'm having a problem because I'm not sure how to echo out an error if there is a problem with with directory.

this is the error I am getting:

Warning: scandir(users/ro/f) [function.scandir]: failed to open dir: No such file or directory in C:\xampp\htdocs\OSO\desktop\main_content\file.php on line 31

This is my code

$folder = $_GET['file_folder'];
$directory = "users/$username/$folder";
if (scandir($directory, 0)) {
    unset($documents[0], $docum开发者_如何学Pythonents[1]);
    $documents = scandir($directory, 0);

    // for each loop
} else {
    echo "No such directory";
}

Cheers in advance


I would first check whether $directory exists using is_dir() before calling scandir():

if (is_dir($directory)) {
    $filenames = scandir($directory, 0);
    // do something
} else {
    echo "No such directory";
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜