Welcome Guest, Not a member yet? Register   Sign In
Codeignier 3 blog application: update() post method needs improvement
#3

(This post was last modified: 05-02-2018, 01:31 PM by Ajax30.)

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?
Reply


Messages In This Thread
RE: Codeignier 3 blog application: update() post method needs improvement - by Ajax30 - 05-02-2018, 12:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB