I don't want the default.jpg image to be uploaded if nothing else is loaded at update post. This already happens at
create post. (Every post has either a relevant image or the default image. No post is without image.)
Code:
public function create() {
$this -> form_validation -> set_rules('title', 'Title', 'required');
$this -> form_validation -> set_rules('desc', 'Short description', 'required');
$this -> form_validation -> set_rules('body', 'Body', 'required');
$this -> form_validation -> set_error_delimiters('<p class="error">', '</p>');
if ($this -> form_validation -> run() === FALSE) {
$this -> load -> view('partials/header', $data);
$this -> load -> view('create');
$this -> load -> view('partials/footer');
} else {
// Upload image
$config['upload_path'] = './assets/img/posts';
$config['allowed_types'] = 'jpg|png';
$config['max_size'] = '2048';
$this -> load -> library('upload', $config);
if (!$this -> upload -> do_upload()) {
$errors = array('error' => $this -> upload -> display_errors());
$post_image = 'default.jpg';
} else {
$data = array('upload_data' => $this -> upload -> data());
$post_image = $_FILES['userfile']['name'];
}
$this -> Posts_model -> create_post($post_image);
redirect('posts');
}
}
I want nothing to change unless a new image is uploaded. How would you do that?