donjd86266 2018-08-24 21:53
浏览 49
已采纳

Codeigniter应用程序更新像wordpress

I have created a project with Codeigniter. I want to add a system that can update my project like as Wordpress. Example: Suppose I run Project V.1.0 but when I want to realize V2.0 my client may update my project files via upload zip. I want this system like as Wordpress. And I don't what to use git. Because I have some client. and I want that they download or collect zip file that contains update version's file. And they upload this zip to the server via Codeigniter project and project will update automatically to v2.0

  • 写回答

2条回答 默认 最新

  • duanpasi6287 2018-08-25 03:25
    关注

    As your question is rather broad I will give you a rather broad response; normally I wouldn't even answer these types of questions but I just so happen to have a relevant script I made a while back.

    This is NOT plug and play and has some third-party dependencies from CakePHP that needs to be autoloaded.

    The script creates an image of all the specified folders in an array adds a manifest of files and an identifier file e.g. VERSION 2. The image (zip file) can then be uploaded to a site running VERSION 1 as long as it has the same update model. Once uploaded, the model then extracts the files as long as the zip has a valid identifier file in it (to prevent users from uploading an unrelated zip and nuking the system); the script also creates a current image of the site (at VERSION 1) just in case restoration is necessary.

    The script also has a restore previous version function that will remove any additional files that were in version 2 and not 1 and will restore the original files of 1.

    I offer no support for this. But hopefully you find it a bit helpful - it's sort of hacked together but in my limited testing it worked fine.

    Controller:

    <?php
    
    if (!defined('BASEPATH')) {
        exit('No direct script access allowed');
    }
    
    /**
     * 
     * NEOU CMS v4 CI Edition
     * @copyright (c) 2018, Alexander Fagard
     * @requires PHP version >= 5.6
     * 
     * You cannot redistribute this document without written permission from the author
     * 
     */
    class Update extends MY_Backend {
    
        static $perm = ['admin_only' => true];
    
        public function __construct() {
            parent::__construct();
            $this->lang->load('core_update');
            $this->load->model('backend/core_update_model', 'update');
        }
    
        public function index() {
            $this->tpl->head($this->lang->line('update_heading'));
            $this->tpl->body();
            $this->output->append_output($this->messages->display());
            $data = array(
                'is_local' => $this->localization->is_local(),
                'previous_exist' => $this->update->previous_exists()
            );
            $this->parser->parse('backend/core_update', $data);
            $this->tpl->footer();
        }
    
        public function restore() {
            try {
                $this->update->restore_previous();
                rmdir_recursive($this->update->updates_folder);
                $this->messages->success($this->lang->line('update_previous_restored'));
            } catch (Exception $e) {
                $this->messages->error($e->getMessage());
            } finally {
                redirect(CMS_DIR_NAME . '/update');
            }
        }
    
        public function apply() {
            $this->load->helper('byte_helper');
            try {
                $this->update->mk_update_dir();
                $config['upload_path'] = $this->update->updates_folder;
                $config['overwrite'] = true;
                $config['allowed_types'] = 'zip';
                $config['max_size'] = convert_bytes_to_type(file_upload_max_size(), 'KB');
                $config['file_ext_tolower'] = true;
                $this->load->library('upload', $config);
                if (!$this->upload->do_upload('update')) {
                    throw new Exception($this->upload->display_errors('', ''));
                }
                $data = $this->upload->data();
                $this->update->apply_update($data['full_path']);
                $this->messages->success($this->lang->line('update_applied'));
            } catch (Exception $e) {
                $this->messages->error($e->getMessage());
            } finally {
                redirect(CMS_DIR_NAME . '/update');
            }
        }
    
        public function create() {
            if (!$this->localization->is_local()) {
                show_error($this->lang->line('update_localhost'), 500);
            }
            try {
                $this->update->create_update();
                $this->messages->success(sprintf($this->lang->line('update_created'), $this->update->files_processed));
            } catch (Exception $e) {
                $this->messages->error($e->getMessage());
            } finally {
                redirect(CMS_DIR_NAME . '/update');
            }
        }
    
    }
    

    Model: https://pastebin.com/UuzQ1tds

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动