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');
}
}