如何使用 php 在图像 url 的最后一部分之前添加 "thumbs"?
how to add "thumbs" befor last part of image url with php?
我的url是这样的:
http://mydomain/filemanager/photos/shares/xxxx/image.jpg
我需要将此图像 url 转换为:
http://mydomain/filemanager/photos/shares/xxxx/thumbs/image.jpg
我该怎么做?
如果您知道文件名(即 image.jpg
)是什么:
str_replace('image.jpg', 'thumbs/image.jpg', $fullPath)
找出文件名相当容易:
basename($fullPath)
放在一起
$fileName = basename($fullPath);
$newFileName = 'thumbs/' . $filename;
$newPath = str_replace($filename, $newFileName, $fullPath);
我的url是这样的:
http://mydomain/filemanager/photos/shares/xxxx/image.jpg
我需要将此图像 url 转换为:
http://mydomain/filemanager/photos/shares/xxxx/thumbs/image.jpg
我该怎么做?
如果您知道文件名(即 image.jpg
)是什么:
str_replace('image.jpg', 'thumbs/image.jpg', $fullPath)
找出文件名相当容易:
basename($fullPath)
放在一起
$fileName = basename($fullPath);
$newFileName = 'thumbs/' . $filename;
$newPath = str_replace($filename, $newFileName, $fullPath);