Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter:如果我没有';我不想更新_Php_Image_Codeigniter_Insert Update - Fatal编程技术网

Php Codeigniter:如果我没有';我不想更新

Php Codeigniter:如果我没有';我不想更新,php,image,codeigniter,insert-update,Php,Image,Codeigniter,Insert Update,我在更新图像时遇到了一个问题。我已经创建了图像上传,工作良好,但我也希望它被更新。当我添加需要的图像时,它会正确更新,但如果我不想更改图像并保持原样,则无法检索我的当前图像。请帮帮我 这是我的密码: 控制器: function edit_product($product_id) { $data = array('recipe_info' => $this->products_model->getRcipe($this->uri->segment(3)),

我在更新图像时遇到了一个问题。我已经创建了图像上传,工作良好,但我也希望它被更新。当我添加需要的图像时,它会正确更新,但如果我不想更改图像并保持原样,则无法检索我的当前图像。请帮帮我

这是我的密码:

控制器:

 function edit_product($product_id) 
{
    $data = array('recipe_info' => $this->products_model->getRcipe($this->uri->segment(3)),
                  'product_id'  => $this->uri->segment(3)
        );
    /*var_dump($data); die();*/
    $this->load->view('edit_product', $data);
}

public function save_edit_recipe()
{
    $thumnail="";
    $stats = "";
    $msg = "";
    $filename = 'r_image';
    $data = array(
                      'recipe_id'       => $this->uri->segment(3),
                      'r_name'          => $this->input->post('r_name'),
                      'r_image'         => '',
                      'r_description'   => $this->input->post('r_description'),
                      'time_id'         => $this->input->post('cooking_time'),
                      'r_cal'           => $this->input->post('calories'),
                      'r_serve'         => $this->input->post('serving_size'),
                      'r_procedure'     => $this->input->post('recipe_procedure') 


    );
    $recipe_id = $this->products_model->update_product($this->uri->segment(3), $data);

    foreach($this->input->post('ingredients') as $key => $value)
    {
        $menuData[] = array('recipe_id'         => $this->input->post('recipe_id'),
                            'ingredient_id'     => $value,
                            'category_id'       => $this->input->post('recipe_category')
        );
    }

    $this->products_model->saveMenu($menuData);

    $config['upload_path'] = 'img/recipes/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = 1024 * 8 ;
    $config['encrypt_name'] = true;

    $this->load->library('upload',$config);
    if (!$this->upload->do_upload($filename))
    {
        $stats = 'error';
        $msg = $this->upload->display_errors('', '');
    }else{
        $uploadData = $this->upload->data('file_name');
        if($uploadData['file_name'])
        {
            $thumnail = 'img/recipes/'.$uploadData['file_name'];
        }else{
            $thumnail = 'No thumnbail uploaded!';
        }

        $updateThumbData = array('recipe_id' => $this->input->post('recipe_id'),
                                 'r_image'   => $thumnail
            );

        $this->products_model->updataRecipeThumnail($updateThumbData);

  }
   redirect('dashboard');

}
型号:

   function getRcipe($recipe_id)
{
    $this->db->where('recipe_id', $recipe_id);
    $query = $this->db->get('recipe');
    return $query->result();
}

   public function update_product($product_id, $data)
{
    $this->db->where('recipe_id', $product_id);
    $this->db->update('recipe', $data);
}

public function updataRecipeThumnail($data)
{
    $this->db->where('recipe_id', $data['recipe_id']);
    $this->db->update('recipe', $data);
}

我已经更新了你的脚本…请使用此功能。。。那么你的问题可能是短路了

 public function save_edit_recipe()
{
    $thumnail="";
    $stats = "";
    $msg = "";
    $filename = 'r_image';
    $data = array(
                      'recipe_id'       => $this->uri->segment(3),
                      'r_name'          => $this->input->post('r_name'),
                      'r_description'   => $this->input->post('r_description'),
                      'time_id'         => $this->input->post('cooking_time'),
                      'r_cal'           => $this->input->post('calories'),
                      'r_serve'         => $this->input->post('serving_size'),
                      'r_procedure'     => $this->input->post('recipe_procedure') 


    );
    $recipe_id = $this->products_model->update_product($this->uri->segment(3), $data);

    foreach($this->input->post('ingredients') as $key => $value)
    {
        $menuData[] = array('recipe_id'         => $this->input->post('recipe_id'),
                            'ingredient_id'     => $value,
                            'category_id'       => $this->input->post('recipe_category')
        );
    }

    $this->products_model->saveMenu($menuData);

    $config['upload_path'] = 'img/recipes/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = 1024 * 8 ;
    $config['encrypt_name'] = true;

    $this->load->library('upload',$config);
    if (!$this->upload->do_upload($filename))
    {
        $stats = 'error';
        $msg = $this->upload->display_errors('', '');
    }else{
        $uploadData = $this->upload->data('file_name');
        if($uploadData['file_name'])
        {
            $thumnail = 'img/recipes/'.$uploadData['file_name'];
           $updateThumbData = array(
                               'recipe_id' => $this->input->post('recipe_id'),
                                 'r_image'   => $thumnail
            );

        $this->products_model->updataRecipeThumnail($updateThumbData);


        }else{
            $thumnail = 'No thumnbail uploaded!';
        }


  }
   redirect('dashboard');

}