Home > Article > Backend Development > PHP rename and copy files_PHP tutorial
php rename and copy files
$nname = $nowpath.$newfilename;
if (file_exists($nname) || !file_exists($oldname)) {
m($nname.' The target file already exists or the original file does not exist');
} else {
m(basename($oldname).' Rename'.basename($nname).(@rename($oldname,$nname) ? 'Success' : 'Failure'));
}
}
// Copy file
elseif ($sname && $tofile) {
if (file_exists($tofile ) || !file_exists($sname)) {
m('The target file already exists or the original file does not exist');
} else {
m(basename($tofile).' copied '. (@copy($sname,$tofile) ? basename($tofile).' Success' : 'Failure'));
}