2020年4月12日
<?phpvar_dump(DIRECTORY_SEPARATOR);var_dump(PATH_SEPARATOR);var_dump(PHP_EOL);var_dump("\r\n");$path = "C:\phpstudy_pro\www\index.html";echo"<pre>";$arr = pathinfo($path);var_dump($arr);var_dump($arr["extension"]);echo"<pre>"$path="C:\phpstudy_pro\www\img";$f=opendir($path);var_dump($f);echo"<hr>";$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);rewinddir($f);$res=readdir($f);var_dump($res);$res=readdir($f);var_dump($res);$res=readdir($f);var_dump($res);$res=readdir($f);var_dump($res);$res=readdir($f);var_dump($res);echo"</pre>";$path="C:\phpstudy_pro\www\img";$f=opendir($path);while($filename=readdir($f)){$dirPath=$path. '/' .$lilename;echo"-----------------<br>";echo"文件名:{$filename}<br>";echo"大小:.filesize($dirPath) . <br>";echo"类型:.filetype($dirPath) . <br>";echo"创建时间:.date('Y-m-d H:i:s',filectime($dirPath)) . <br>";echo"-----------------<br>";}closedir($f);php2<?phpvar_dump(DIRECTORY_SEPARATOR);var_dump(PATH_SEPARATOR);var_dump(PHP_EOL);var_dump("\r\n");$path = "C:\phpstudy_pro\www\index.html";echo"<pre>";$arr = pathinfo($path);var_dump($arr);var_dump($arr["extension"]);echo"<pre>"$path="C:\phpstudy_pro\www\img";$f=opendir($path);var_dump($f);echo"<hr>";$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);rewinddir($f);$res=readdir($f);var_dump($res);$res=readdir($f);var_dump($res);$res=readdir($f);var_dump($res);$res=readdir($f);var_dump($res);$res=readdir($f);var_dump($res);echo"</pre>";$path="C:\phpstudy_pro\www\img";$f=opendir($path);while($filename=readdir($f)){$dirPath=$path. '/' .$lilename;echo"-----------------<br>";echo"文件名:{$filename}<br>";echo"大小:.filesize($dirPath) . <br>";echo"类型:.filetype($dirPath) . <br>";echo"创建时间:.date('Y-m-d H:i:s',filectime($dirPath)) . <br>";echo"-----------------<br>";}closedir($f);php3<?phpvar_dump(DIRECTORY_SEPARATOR);var_dump(PATH_SEPARATOR);var_dump(PHP_EOL);var_dump("\r\n");$path = "C:\phpstudy_pro\www\index.html";echo"<pre>";$arr = pathinfo($path);var_dump($arr);var_dump($arr["extension"]);echo"<pre>"$path="C:\phpstudy_pro\www\img";$f=opendir($path);var_dump($f);echo"<hr>";$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);$res= readdir($f);var_dump($res);rewinddir($f);$res=readdir($f);var_dump($res);$res=readdir($f);var_dump($res);$res=readdir($f);var_dump($res);$res=readdir($f);var_dump($res);$res=readdir($f);var_dump($res);echo"</pre>";$path="C:\phpstudy_pro\www\img";$f=opendir($path);while($filename=readdir($f)){$dirPath=$path. '/' .$lilename;echo"-----------------<br>";echo"文件名:{$filename}<br>";echo"大小:.filesize($dirPath) . <br>";echo"类型:.filetype($dirPath) . <br>";echo"创建时间:.date('Y-m-d H:i:s',filectime($dirPath)) . <br>";echo"-----------------<br>";}closedir($f);
笔记:
相对路径与绝对路径:
相对路径:
参照当前文件夹来寻找文件
1.php
C:\phpstudy_pro\WWW
C:\phpstudy_pro
绝对路径:
根据系统的根目录来寻找文件
window根目录=> C: D:E:
路径分隔符
文件夹之间的分隔符
window是使用\来作为路径分隔符
macbook是使用/来作为路径分隔符
使用系统定义的常量来解决(根据系统而改变)
DIRECTORY_SEPARATOR 路径分隔符 w:\ l:/
PATH_SEPARATOR (环境变量设置)分隔符 w:;l: :
PHP_EOL 换行符 w: \r\n l: \n
不同的根路径
不同的系统它的根路径不一样
window:c: d: e:
linux: /
路径解析函数
dirname()
basename()
pathinfo()
遍历目录
opendir() 打开一个目录
readdir() 从打开的目录中获取一个文件或文件夹的名字
closedir() 关闭打开的目录
rewinddir() 重置目录指针
