重命名时将'art_ID'绑定到图像

时间:2015-05-26 18:56:14

标签: php file rename

如何重命名文件夹中的所有图像,并将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

关于如何解决这个问题的任何想法?

0 个答案:

没有答案