rename()函数可以重命名文件、目录等,但是要注意目的地和起始地址的编码。
比如:我的PHP文件编码是UTF-8,但是在WINDOW系统中中文默认编码是GBK,因此我应该这样写
$newFileName\$filename是UTF-8编码.
rename(iconv('UTF-8','GBK',$dir.$filename), iconv('UTF-8','GBK',$dir.$newFileName));
$old_filename = "test/66/可颂1.png";
$new_filename = "test/66/x1.png";
rename(iconv('UTF-8','GBK',$old_filename), iconv('UTF-8','GBK',$new_filename));
也和PHP文件自身的编码有关,如果本身就是GBK文件,那就不用转了。
//rename(iconv('UTF-8','GBK',$old_filename), iconv('UTF-8','GBK',$new_filename));
rename($old_filename, $new_filename);