- 代码:
/*
@desc:获取路径信息
@param path 传入路径,如a/b/c.jpg
@return info dir:路径,name:文件名,suffix:后缀名
*/
function fileinfo($path){
$dir = dirname($path);
$name = basename($path);
$suffix = pathinfo($path,PATHINFO_EXTENSION);
$info = array(
'dir'=>$dir,
'name'=>$name,
'suffix'=>$suffix
);
return $info;
}
- 测试:
$ret = fileinfo('a/b/c.jpg');
var_dump($ret);
- 输出:
array(3) {
["dir"]=>
string(3) "a/b"
["name"]=>
string(5) "c.jpg"
["suffix"]=>
string(3) "jpg"
}
|