【发布时间】:2017-07-24 01:41:39
【问题描述】:
虽然这很有效,但正在寻找一种让它变得更干净一点/很多的方法,并在此过程中学习!!! 我将 /thumbs 添加到目录和文件字符串,并将 _thumb 添加到同一字符串的文件名末尾。
从此... Gallery/Test/Image/image.jpg
到这个... Gallery/Test/Image/thumbs/image_thumb.jpg
但是路径的长度可以根据目录结构而改变,但是 /thumbs 总是最后一个目录,_thumb 总是在“.”之前
$thumb_dir = substr($file, 0, strrpos($file, '/')) . '/thumbs' . substr($file, strrpos($file, '/'));
$thumbnail = substr($thumb_dir, 0, strrpos($thumb_dir, '.')) . '_thumb' . substr($thumb_dir, strrpos($thumb_dir, '.'));
谢谢
【问题讨论】:
-
您也可以使用正则表达式:3v4l.org/AjNgC 我不会将其作为答案发布,因为接受的答案绝对是更好的解决方案。但我认为这是一种有趣的方法。