如何重命名文件夹中的所有图像,并将art_ID
从我的数据库绑定到新名称,并在有多个图像的情况下添加一些前缀?
这是我试过的:
$directory = 'tmp_img/';
foreach (glob($directory."*.jpg") as $filename) {
$file = realpath($filename);
$result = substr($filename, 0, 19); //takes first 19 characters to replace
//files in the folder have a random 9 digit number (478-391-601.jpg)
rename($file, str_replace($result,"tmp_img/". $item['art_ID'] ,$file));
}
它确实更改了名称但不知何故$item['art_ID']
似乎是一个空字符串,导致tmp_img/.jpg
而不是tmp_img/264330.jpg
关于如何解决这个问题的任何想法?