rename函数一直报错,最后发现是windows下文件名的编码问题,如果项目文件是utf-8的话,一定要经过一步转码
$dir = $path . '/../resource/logo';
$handle = opendir($dir);
$command = Yii::$app->db->createCommand($sql);
while (($file = readdir($handle)) !== false) {
if ($file !== '.' && $file !== '..') {
$file = iconv('gbk', 'utf-8', $file);
$info = pathinfo($file);
$new_name = substr(md5($info['filename']), 0, 15) . '.png';
rename(iconv('utf-8','gbk',$dir.$file),iconv('utf-8','gbk',$dir.$new_name));
}
}
closedir($handle);