dongzhun1857 2013-11-03 09:00
浏览 46
已采纳

CodeIgniter通过tinymce上传图片

I'd like some help please. I have created a form with CodeIgniter where I can write posts and what I 'd like to do is to add the functionality to upload image(s) for this post.

At the beginning I thought to add an input field in my form where I can upload files, so I can display them above the content (text) at the front end, but although this is a very quick and easy solution, may be not so flexible. So I thought to use the 'insert/edit image' button that tinymce has.

I haven’t done this before so how can I upload an image or images through tinymce so that they appear within the text at the front-end??

EDIT Here is my code.

This is my view:

<?php echo form_open_multipart(); ?>
<div>
    <label for="title">Title *</label>
    <?php echo form_input('title', html_escape(set_value('title', $article->title))); ?>
</div>
<div>
    <label for="file">Upload image</label>
    <?php echo form_upload('file'); ?>
</div>
<div>
    <label for="body">Body *</label> // has TinyMce
    <?php echo form_textarea('body', strip(set_value('body', $article->body))); ?>
</div>
<div>
    <?php echo form_submit('save', 'Save'); ?>
</div>
<?php echo form_close(); ?>

This is my model:

public function save($id = null){

        $post_data = array(
                'title' => $this->input->post('title'),
                'file' => $this->input->post('file'),
                'body' => $this->input->post('body'), 
                );

        return parent::save($post_data, $id);
    }

This is the controller:

public function article($id = null){

        ....

        $this->form_validation->set_rules($this->article_model->rules);

        // Process the form
        if ($this->form_validation->run() == TRUE) {
            $this->article_model->save($id);
            redirect('admin/article');
        }
    }
  • 写回答

2条回答 默认 最新

  • douyou7878 2013-11-03 11:07
    关注

    There are two approaches to this.

    You either keep an upload field outside TinyMCE and use ajax/iframe file upload.

    OR

    Write a TinyMCE plugin with an ability to upload an image.

    Please note that both of these approaches take some effort to implement.

    As far as handling the file on the server side is concerned, you can go through the Codeigniter Docs to get you started.

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

报告相同问题?

悬赏问题

  • ¥20 Java-Oj-桌布的计算
  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路