2016-07-19 11 views
0

データベースに画像(パスのみ)を挿入したいと思います。このコードを書きましたが、default.png(パスのみ)を挿入するたびにここに書きました。他の画像も挿入したい。データベースに画像(パスのみ)を挿入

$maxId = $this->user_master_m->get_max_product_id(); 
        $new_file = "defualt.png"; 
        if ($_FILES["image"]['name'] != "") { 
         $file_name = $_FILES["image"]['name']; 
         $file_name_rename = 'P-' . $maxId->id; 
         $explode = explode('.', $file_name); 
         if (count($explode) >= 2) { 

          $new_file = $file_name_rename . '.' . $explode[1]; 
          $config['upload_path'] = "./uploads/images"; 
          $config['allowed_types'] = "gif|jpg|png"; 
          $config['file_name'] = $new_file; 
          $config['max_size'] = '1024'; 
          $config['max_width'] = '3000'; 
          $config['max_height'] = '3000'; 
          $array['product_image'] = $new_file; 
          $this->load->library('upload', $config); 
          if (!$this->upload->do_upload("image")) { 
           $this->data["image"] = $this->upload->display_errors(); 
           $this->data["subview"] = "admin_view/product_form_view"; 
           $this->load->view('_layout_main', $this->data); 
          } else { 
           $data = array("upload_data" => $this->upload->data()); 
           $this->user_master_m->add_product_m($array); 

          } 
         } else { 
          $this->data["image"] = "Invalid file"; 
          $this->data["subview"] = "admin_view/product_form_view"; 
          $this->load->view('_layout_main', $this->data); 
         } 
        } else { 
         $array["product_image"] = $new_file; 
         $this->user_master_m->add_product_m($array); 
        } 
+0

最初にvar_dump($ _FILES ["image"] ['name'])をチェックし、結果を –

+0

に追加してください。フォームがform_open_multipart()でない場合は、$ _FILESにアクセスできません – pradeep

+0

.. –

答えて

0

あなたが適切かどうかの画像を取得しているかどうかを確認するために

print_r($_FILES);

で$ _FILESを印刷してみます。

+0

よろしくお願いします....ありがとう.. –

関連する問題