PHP获取图像的文件路径?
例如: 图像url:PHP获取图像的文件路径?,php,Php,例如: 图像url: localhost/example/folder/filename.jpg 我想获得图像的路径,因此它必须是: localhost/example/folder/ 怎么做 我英语说得不好。谢谢 我找到了一个解决方案,而不是使用dirname: $image = 'localhost/example/folder/filename.jpg'; $directory = substr($image, 0, strrpos($image, '/', -2) + 1 ); ec
localhost/example/folder/filename.jpg
我想获得图像的路径,因此它必须是:
localhost/example/folder/
怎么做
我英语说得不好。谢谢强>
我找到了一个解决方案,而不是使用dirname:
$image = 'localhost/example/folder/filename.jpg';
$directory = substr($image, 0, strrpos($image, '/', -2) + 1 );
echo $directory;
//return: localhost/example/folder/
使用dirname()
要获取文件的父文件夹:
dirname("localhost/example/folder/filename.jpg");
请参阅:使用dirname('localhost/example/folder/filename.jpg')。这可能会有帮助:
dirname("localhost/example/folder/filename.jpg");