Error submitting a form with upload pic option. PHP Codeigniter

تعرفه تبلیغات در سایت

آخرین مطالب

امکانات وب

I've been trying to upload a pic to a folder and store its path in the database, my code seems to work correctly, but no it's not, After i click submit button, it goes to a blank page. Using Inspect element, Network option in my browser, when seeing the parameters sent I see correct input from the text fields but for the image, Content-Disposition: form-data; name="myimage"; filename="IMG_8971.JPG" Content-Type: image/jpeg Plus some other weirly looking characters and symbols like :

ÿØÿà

CONTROLLER:

private function setup_upload_option()
{
    $config = array();
    $config['upload_path'] = 'blog/uploads/';
    $config['allowed_type']='jpg|jpeg|png|gif';
    $config['encrypt_name']= TRUE;
    $config['overwrite']=FALSE;

    return $config;
}
public function post_new_blog()
{
    $this->form_validation->set_rules('title', 'Title of the Blog', 'trim|required');
    $this->form_validation->set_rules('desc', 'Content of the Blog', 'trim|required');
    $this->form_validation->set_rules('tags', 'Tags fo the blog', 'trim|required');

    if($this->form_validation->run()==FALSE) {
        $this->session->set_flashdata('fail', validation_errors());
        $this->load->view('blogsection/addblog', array('logged_in' => $this->logged_in));
    }
    else {
        $this->load->library('upload');

        $files = $_FILES;
        $count = count($_FILES['myimage']['name']);


        for($i=0; $i<$count ;$i++)
        {
            $_FILES['myimage']['name'] = $files['myimage']['name'][$i];
            $_FILES['myimage']['type'] = $files['myimage']['type'][$i];
            $_FILES['myimage']['size'] = $files['myimage']['size'][$i];
            $_FILES['myimage']['tmp_name'] = $files['myimage']['tmp_name'][$i];

            $this->upload->initialize($this->setup_upload_option());

            if($this->upload->do_upload()==TRUE)
            {
                $data = $this->upload->data();
                $config1['image_library'] = 'gd2';
                $config1['source_image']  = $data['full_path'];
                $config1['new_image']     = 'blog/uploads/thumbs/';
                $config1['create_thumb']  = false;
                $config1['height']        = 200;
                $config['width']          = 200;

                $this->load->library('image_lib', $config1);
                $this->image_lib->initialize($config1);
                $this->image_lib->resize();

                $mydata = $this->session->all_userdata();
                $dataarray = array(
                    'blog_title' => $this->input->post('title', true),
                    'blog_content' => $this->input->post('desc', true),
                    'blog_tags' => $this->input->post('tags', true),
                    'blog_image_name' => $data['orig_name'],
                    'blog_image' => $data['full_path'],
                    'date_posted' => date(" jS of F Y "),
                    'posted_by' => $mydata['username']
                );

                $this->main_model->save_new_posts($dataarray);

                $this->load->view('blogsection/addblog', array('logged_in' => $this->logged_in, 'success' => 'Blog was posted successfully',$dataarray));


            }
        }

    }

}

MODEL:

public function save_new_posts($dataarray)
{
    $this->db->insert('blogs', $dataarray);
    if($this->db->affected_rows()>0)
    {
        return true;
    }
}

نویسنده : استخدام کار بازدید : 83 تاريخ : چهارشنبه 3 خرداد 1396 ساعت: 2:34

فهرست وبلاگ