Public Function Changecovername () {
$type = ' postgraduate examination ';
$coverPath = './public/course_cover/kaoyan/';
$type = ' Level 46 ';
$coverPath = './public/course_cover/four-six/';//source Directory
$targetPath = './upload/img/course_img/cover/'. MD5 ($type). ' /';//target directory
Moving files
$this->recursecopy ($coverPath, $targetPath);
Renamed file after move
$this->changename ($targetPath);
}
Move file functions
//directory file movement, concise and efficient
Public function recursecopy ($SRC, $DST) {//original directory, copied to the directory
$dir = Opendir ($SRC);
@mkdir ($DST);
while (false!== ($file = Readdir ($dir))) {
if ($file! = ') && ($file! = ' ... ')) {
if (Is_dir ($src. ‘/‘ . $file) {
$this->recursecopy ($src. ‘/‘ . $file, $dst. ‘/‘ . $file);
}
Else {
Copy ($src. ‘/‘ . $file, $dst. ‘/‘ . $file);
}
}
}
Closedir ($dir);
}
renaming function
Public Function ChangeName ($targetPath) {
$d = Dir ($targetPath);
while (false!== ($entry = $d->read ())) {
$NEWSTR = Explode ('. ', $entry);
$newStr [0] = iconv (' GBK ', ' utf-8 ', $newStr [0]);
$newName = MD5 ($newStr [0]);
echo $newStr [0]. ' ---'. $newName. ' <br/> ';
Rename ($targetPath. $entry, $targetPath. $newName. ".". $NEWSTR [1]);
}
$d->close ();
}
PHP Bulk Move File renaming