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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?