PHP文件操作之获取目录下文件与计算相对路径的方法
获取目录下文件1、获取目录下文件,不包括子目录//打印所有文件名 foreach ($filens as $value) { echo $value." "; } 2、获取目录下所有文件,包括子目录 read()){ if($file !="." && $file !=".."){ get_allfiles($path."/".$file,$files); } } $dp ->close(); } if(is_file($path)){ $files[] = $path; } }function get_filenamesbydir($dir){ $filenames = get_filenamesbydir("static/image/"); 计算两个文件之间的相对路径方法php 计算两个文件之间的相对路径方法例如: 文件A 的路径是 /home/web/lib/img/cache.php 文件B的路径是 /home/web/api/img/show.php 那么,文件A相对于文件B的路径是 ../../lib/img/cache.php,即文件B 访问 文件A的相对路径。 function getRelativePath // 获取相同路径的部分$intersection = array_intersect_assoc($arr1,$arr2); $depth = 0; for($i=0,$len=count($intersection); $i<$len; $i++){ // 将path2的/ 转为 ../,path1获取后面的部分,然后合拼 $relativePath = implode('/',$tmp); return $relativePath; demo echo getRelativePath($path1,$path2); // ../../lib/img/cache.php ?> (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
