简体   繁体   English

PHP从目录中读取文件

[英]Php reading files from directory

I have this code which reads files from directory: 我有这段代码从目录读取文件:

//directory to read
$dir = ($_REQUEST['dir']);

if(file_exists($dir)==false){
    echo 'Directory \'', $dir, '\' not found!';
}else if( !is_readable($dir) ) {
    echo 'Directory \'', $dir, '\' is not readable! Check your permissions.';
}else{

    $di = new RecursiveDirectoryIterator($dir);
    foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
        $file_type = explode(".", $filename);
        $extension = strtolower(array_pop($file_type));
        if(in_array($extension, $allowed_files) == true){
            $mediaArr[] = $filename;
        }
    }
    echo json_encode($mediaArr);
}

If I enter path as this: http://www.mydomain.com/some_folder/ 如果我这样输入路径: http : //www.mydomain.com/some_folder/

I get an error "Directory http://www.mydomain.com/some_folder/ not found" 我收到错误消息“找不到目录http://www.mydomain.com/some_folder/

Why is this? 为什么是这样?

The PHP file system functions work with file system paths. PHP文件系统功能可用于文件系统路径。 There are different protocol wrappers you can use with the file system functions, but I don't see how they would be of any help here. 您可以将不同的协议包装程序与文件系统功能一起使用,但在这里我看不到它们会有什么帮助。

Just use the file system paths. 只需使用文件系统路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM