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条)

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧