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 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答