public function move_file($nv_update_config, $files)
{
if (empty($files)) {
return true;
}
global $global_config;
$is_ftp = false;
if ($global_config['ftp_check_login'] == 1) {
$ftp_server = nv_unhtmlspecialchars($global_config['ftp_server']);
$ftp_port = intval($global_config['ftp_port']);
$ftp_user_name = nv_unhtmlspecialchars($global_config['ftp_user_name']);
$ftp_user_pass = nv_unhtmlspecialchars($global_config['ftp_user_pass']);
$ftp_path = nv_unhtmlspecialchars($global_config['ftp_path']);
$ftp = new NukeViet\Ftp\Ftp($ftp_server, $ftp_user_name, $ftp_user_pass, array('timeout' => 20), $ftp_port);
if (empty($ftp->error) and $ftp->chdir($ftp_path)) {
$is_ftp = true;
}
}
// Nhat ki
$logs_message = array();
$logs_status = array();
// Bat dau tao thu muc
foreach ($files as $file_i) {
$cp = '';
$e = explode('/', $file_i);
foreach ($e as $p) {
if (!empty($p) and is_dir(NV_ROOTDIR . '/install/update/' . $cp . $p) and !is_dir(NV_ROOTDIR . '/' . $cp . $p)) {
// Neu khong tao thu muc theo cach thong thuong thi tao bang FTP (neu co)
if (@mkdir(NV_ROOTDIR . '/' . $cp . $p) == false and $is_ftp === true) {
$ftp->mkdir($cp . $p);
}
if (!is_dir(NV_ROOTDIR . '/' . $cp . $p)) {
// Nhat ki that bai
$logs_message[] = $this->lang['update_log_creat_dir'] . ' ' . $cp . $p;
$logs_status[] = false;
// Luu nhat ki
$this->log($nv_update_config, $logs_message, $logs_status);
if ($is_ftp === true) {
$ftp->close();
}
return $this->lang['update_error_creat_dir'] . ' ' . $cp . $p;
}
// Nhat ki thanh cong
$logs_message[] = $this->lang['update_log_creat_dir'] . ' ' . $cp . $p;
$logs_status[] = true;
}
$cp .= $p . '/';
}
}
// Di chuyen cac file
foreach ($files as $file_i) {
if (is_file(NV_ROOTDIR . '/install/update/' . $file_i)) {
// Neu ton tai thi xoa truoc
if (file_exists(NV_ROOTDIR . '/' . $file_i)) {
if (@unlink(NV_ROOTDIR . '/' . $file_i) == false and $is_ftp === true) {
// Dung ftp de xoa
$ftp->unlink($file_i);
}
}
// Di chuyen bang cach doi ten duong dan
if (@rename(NV_ROOTDIR . '/install/update/' . $file_i, NV_ROOTDIR . '/' . $file_i) == false and $is_ftp === true) {
// Dung ftp di chuyen
$ftp->rename('install/update/' . $file_i, $file_i);
}
if (file_exists(NV_ROOTDIR . '/install/update/' . $file_i)) {
// Nhat ki that bai
$logs_message[] = $this->lang['update_log_move_file'] . ' ' . $file_i;
$logs_status[] = false;
// Luu nhat ki
$this->log($nv_update_config, $logs_message, $logs_status);
if ($is_ftp === true) {
$ftp->close();
}
return $this->lang['update_error_move_file'] . ' ' . $file_i;
}
// Nhat ki thanh cong
$logs_message[] = $this->lang['update_log_move_file'] . ' ' . $file_i;
$logs_status[] = true;
}
}
//Resets the contents of the opcode cache
if (function_exists('opcache_reset')) {
opcache_reset();
}
// Luu nhat ki
$this->log($nv_update_config, $logs_message, $logs_status);
return true;
}