2017-11-08 12 views
0

codeignitorのコピー先フォルダに画像をアップロードできません。コントローラ/管理フォルダの下にsiteという名前のコントローラを1つ作成しました。モデルフォルダの下に1つのモデルを追加しました。 view_addsiteという名前のviewフォルダに1つのビューを作成しました。私はmysqlの中にsitesettingsという名前のテーブルを1つ作成し、そのテーブルに14個のカラムが追加されています。テーブル内のimage.pleaseを除いて、コードを見つけて助けてください。詳細についてcodeignitorで画像をアップロードする方法

  controller(site):: 
      =========== 
     public function add() 
      { 

     $datte = date('Y-m-d H:i:s'); 
     if(!$this->input->post('buttonSubmit')) 
     { 
      $data['message'] = ''; 
      $this->load->view('admin/view_addsite', $data); 
     } 
     else 
     { 
      //$this->load->library('form_validation'); 
      if($this->form_validation->run('addsite')) 
      { 
        $config['upload_path']   = './uploads/'; 
        $config['allowed_types']  = 'gif|jpg|png'; 
       $config['max_width'] = '2048'; 
       $config['max_height'] = '2048'; 
        $this->load->library('upload', $config); 

       $title = $this->input->post('title'); 

      $name = $this->input->post('name'); 
      $admin = $this->input->post('admin'); 
      $mail = $this->input->post('mail'); 
      $phone = $this->input->post('phone'); 
      $contact=$this->input->post('contact'); 
      $fb=$this->input->post('fb'); 
      $tw=$this->input->post('tw'); 
      $yt=$this->input->post('yt'); 
      $in=$this->input->post('in'); 
      $gp=$this->input->post('gp'); 
      $ft=$this->input->post('ft'); 
      $this->upload->do_upload('image'); 
     $data = $this->upload->data('image'); 
     $image= $data['file_name']; 
      $this>model_site> 
       insert($title,$image,$name,$admin,$mail, 
      $phone,$contact,$fb,$tw,$yt,$in,$gp,$ft); 
      $this->session->set_flashdata('message','site Successfully 
      Created.'); 
      redirect(base_url('admin/site')); 
     } 
     else 
     { 
      $data['message'] = validation_errors(); 
      $this->load->view('admin/view_addsite', $data); 
     } 
     } 
     } 


      Model(model_site):: 
      =================== 


       public function 
      insert($title,$image,$name,$admin,$mail,$phone,$contact, 
       $fb,$tw,$yt,$in,$gp,$ft) 
       { 
       $data = array(
     'admintitle' => $title, 
     'logo' => $image, 
     'fromname' => $name, 
      'adminemail'=> $admin, 
      'receivemail' => $mail, 
      'phonenumber' => $phone, 
      'contactaddress' => $contact, 
      'facebook' => $fb, 
      'twitter'=>$tw, 
      'youtube' => $yt, 
      'instagram' => $in, 
      'googleplus' => $gp, 
      'footer' => $ft, 
     ); 
      $this->db->insert('sitesettings', $data); 

         } 


       view(view_addsite):: 
        =================== 

        <!-- page content --> 
      <div class="right_col" role="main"> 
      <div class=""> 
       <div class="page-title"> 
       <div class="title_left"> 
      <h3>Sitesettings</h3> 
      </div> 
       </div><div class="clearfix"></div> 
       <hr> 
        <div class="row"> 
        <div class="col-md-12 col-sm-12 col-xs-12"> 
       <div class="x_panel"> 
       <div class="x_title"> 
        <h2>Add a new Site</h2> 
        <ul class="nav navbar-right panel_toolbox"> 
         <li><a class="collapse-link"><i class="fa fa- 
       chevron-up"></i></a></li> 
         <li><a class="close-link"><i class="fa fa-close"> 
       </i></a></li> 
        </ul> 
        <div class="clearfix"></div> 
       </div> 
       <div class="x_content"> 
        <label><?php echo $message; ?></label> 
        <form method="post"> 

         <fieldset> 
          <div class="form-group"> 
        AdminPage Title : <input class="form-control" 
        placeholder="Admin Title" name="title" id="title" 
         type="text" ><span id="user-availability-status"> 
         </span> 

          <div class="form-group"> 

         Select image to upload: 
          <input type="file" name="fileToUpload" 
         id="fileToUpload">&nbsp; 

        </form> 
       <div class="form-group"> 
        From Name : <input class="form-control" 
       placeholder="Form Title" name="name" id="name" type="text" 
       ><span id="user-availability-status"></span> 

           <div class="form-group"> 
       Admin Email Address : <input class="form-control" 
        placeholder="Admin Email" name="admin" id="admin" 
         type="text" onBlur="checkAvailability()" ><span 
        id="user-availability-status"></span> 

           <div class="form-group"> 
       Receive Mail Address for Contact Us Form : <input 
        class="form-control" placeholder="Receive Email" 
       name="mail" id="mail" type="text" 
       onBlur="checkAvailability()" ><span id="user-availability- 
       status"></span> 
          </div> 
           <div class="form-group">  
        Phone number: <input class="form-control" 
        placeholder="Phone Number" name="phone" id="phone" 
        type="text" onBlur="checkAvailability()" ><span id="user- 
        availability-status"></span> 
          </div> 
           <div class="form-group"> 
       Contact Adress : <input class="form-control" 
        placeholder="Contact Address" name="contact" id="contact" 
        type="text" onBlur="checkAvailability()" ><span 
        id="user-availability-status"></span> 
          </div> 
       <div class="form-group"> 
       Facebook : <input class="form-control" placeholder="Facebook" 
       name="fb" id="fb" type="text" onBlur="checkAvailability()" > 
       <span id="user-availability-status"></span> 
          </div> 
           <div class="form-group"> 
       Twitter : <input class="form-control" placeholder="Twitter" 
       name="tw" id="tw" type="text" onBlur="checkAvailability()" > 
        <span id="user-availability-status"></span> 
          </div> 
           <div class="form-group"> 
        Youtube : <input class="form-control" 
       placeholder="Youtube" name="yt" id="yt" type="text" 
       onBlur="checkAvailability()" ><span id="user-availability- 
       status"></span> 
          </div> 
           <div class="form-group"> 
       Instagram : <input class="form-control" 
       placeholder="Instagram" name="in" id="in" type="text" 
       onBlur="checkAvailability()" ><span id="user-availability- 
       status"></span> 
          </div> 
           <div class="form-group"> 
        Google Plus: <input class="form-control" 
       placeholder="Google Plus" name="gp" id="gp" type="text" 
       onBlur="checkAvailability()" ><span id="user-availability- 
       status"></span> 
          </div> 
           <div class="form-group"> 
        Footer: <input class="form-control"     
           placeholder="Footer" name="ft" id="ft"     
       type="text" onBlur="checkAvailability()" ><span id="user- 
       availability-status"></span> 
          </div> 
          <input type="submit" name="buttonSubmit" 
       value="add" class="btn btn-success" /> 
         </fieldset> 
        </form> 
           </div> <!-- /content --> 
         </div><!-- /x-panel --> 
         </div> <!-- /col --> 
         </div> <!-- /row --> 
          </div> 
          </div> <!-- /.col-right --> 
             <!-- /page content --> 


        <?php $this->load->view('admin/partials/admin_footer'); ?> 


       <?php if($this->session->flashdata('message') != NULL) : ?> 
        <script> 
       swal({ 
       title: "Success", 
       text: "<?php echo $this->session->flashdata('message'); ?>", 
        type: "success", 
         timer: 1500, 
           showConfirmButton: false 
           }); 
          </script> 
          <?php endif ?> 

            Thanks in advance. 
+0

あなたはあなたのコードを別々に置くべきです。 – Niroshan

答えて

0
public function do_upload() 
{ 
    $config['upload_path']   = './uploads/'; 
    $config['allowed_types']  = 'gif|jpg|png'; 
    $config['max_size']    = 100; 
    $config['max_width']   = 1024; 
    $config['max_height']   = 768; 
    $this->load->library('upload', $config); 

    if (! $this->upload->do_upload('userfile')) 
    { 
      $error = array('error' => $this->upload->display_errors()); 
      $this->load->view('upload_form', $error); 
    } 
    else 
    { 
      $data = array('upload_data' => $this->upload->data()); 
      $this->load->view('upload_success', $data); 
    } 
} 

参照:upload file with codeigniter

0

をあなたのformタグに にenctype = "multipart/form-データ" が欠落しても、単に画像入力ボックスの後</form>を削除しています。