NvUpdate::move_file PHP Method

move_file() public method

NvUpdate::move_file()
public move_file ( mixed $nv_update_config, mixed $files )
$nv_update_config mixed
$files mixed
    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;
    }

Usage Example

Esempio n. 1
0
 // Danh sach cac file con lai
 $array['file_list'] = $NvUpdate->list_all_file();
 // Buoc tiep theo
 if (!file_exists(NV_ROOTDIR . '/install/update_docs_' . NV_LANG_UPDATE . '.html')) {
     $array['NextStepUrl'] = NV_BASE_SITEURL . 'install/update.php?step=3';
 } else {
     $array['NextStepUrl'] = NV_BASE_SITEURL . 'install/update.php?step=2&substep=5';
 }
 // Di chuyen cac file
 if ($nv_Request->isset_request('move', 'get')) {
     if (!isset($nv_update_config['updatelog']['is_start_move_file'])) {
         // Danh dau da di chuyen cac file roi
         $nv_update_config['updatelog']['is_start_move_file'] = NV_CURRENTTIME;
         $NvUpdate->set_data_log($nv_update_config['updatelog']);
     }
     $check = $NvUpdate->move_file($nv_update_config, $array['file_list']);
     if ($check === true) {
         if (!file_exists(NV_ROOTDIR . '/install/update_docs_' . NV_LANG_UPDATE . '.html')) {
             $nv_update_config['updatelog']['step'] = 2;
             $NvUpdate->set_data_log($nv_update_config['updatelog']);
         } else {
             $nv_update_config['updatelog']['substep'] = 4;
             $NvUpdate->set_data_log($nv_update_config['updatelog']);
         }
         die('OK');
     } else {
         die($check);
     }
 }
 // Khong co file nao nua thi luu lai va chuyen buoc 3
 if (empty($array['file_list']) and $nv_update_config['updatelog']['step'] < 2) {