你知道怎么管理吗?我知道可以使用mkdir
函数指定上下文,但是使用这个函数我不能检查路径是否存在,不是吗?
使用file_exists
。http://php.net/manual/en/function.file-exists.php
if (file_exists('path/to/file/or/dir')){
doSomething();
} else {
createFileOrDir();
}
对于远程服务器使用:
is_dir('ftp://user:password@example.com/some/dir/path');
可以将is_dir()
协议与FTP
协议一起使用。你可以测试它:
var_dump(is_dir('ftp://ftp.debian.org/debian/')); // bool(true)
但是,您不能对HTTP
协议做同样的事情:
var_dump(is_dir('http://ftp.debian.org/debian/')); // bool(false)
这是因为HTTP协议没有提供关于远程资源是否标识文件夹或文件的信息。
Update: HTTP协议不知道远程资源是否是目录,这是不完全正确的吗?有一个特殊的mime类型定义,服务器可以将其与Content-Type头一起发送,客户端可以检查:
Content-Type: httpd/unix-directory
但是在野外很少使用。大多数web服务器出于安全原因完全禁用目录列表。