2017-10-20 1 views
-1

루트 디렉토리를 만들고 경로를 설정 했으므로 프런트 엔드를 그대로 사용했습니다. ide는 어떤 오류도주지 않고 있지만 진행할 때 어떤 이미지도 선택하지 않았다고 말합니다.codeigniter에서 파일 업로드가되지 않습니다. 오류 : 파일을 선택하지 않았습니다.

컨트롤러 코드 :

class Images extends MY_Controller 
{ 
    function __construct() 
    { 
     parent::__construct(); 
    } 

    function index() 
    { 
     $this->data['displayname'] = $this->admin->lastname; 
     $this->data['images'] = Image::all(); 
     $this->data['btn'] = 'Save'; 
     $this->data['content'] = 'admin/images/index'; 
     $this->load->view('layouts/admin', $this->data); 

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

     if (! $this->upload->do_upload('images')) 
     { 
      $error = array('error' => $this->upload->display_errors()); 
      // echo $this->upload->display_errors(); 
      $this->load->view('index', $error); 
     } 
     else 
     { 
      $data = array('upload_data' => $this->upload->data()); 

      $this->load->view('upload_success', $data); 
     } 

    } 
} 

뷰 코드 : 이것은 당신이

<?php form_open_multipart('admin/images/do_upload') ?> 

하지 않음이를 사용해야 파일 업로드의 경우 파일

<?= form_open('admin/images/do_upload') ?> 
      <label><?= form_upload('images[]')?></label> 
      <div class="input-group-btn"> 
       <button class="btn btn-success add-image" type="button"><i class="glyphicon glyphicon-plus"></i> Add</button> 
      </div> 
     </div> 

    </ul> 

    <div class="line"></div> 

<?= form_submit('', 'Submit', 'class="publish-btn"') ?> 

<?= form_close()?> 
+0

이 시간 – user4419336

답변

0

아니라 후 연구를 많이하고 코드를 많이 시도하고 난 여기에 내 문제 를 해결하는 것은 전체 일 컨트롤러 코드입니다 :

public function create($id) 
    { 
     $config ['upload_path'] = 'uploads'; 
     $config ['allowed_types'] = 'gif|jpg|png'; 
     $config ['encrypt_name'] = TRUE; 

     $this->upload->initialize($config); 
     $package = Package::find($id); 

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

     for ($i = 0; $i < $cpt; $i++) { 

      $_FILES ['images'] ['name'] = $files ['images'] ['name'] [$i]; 
      $_FILES ['images'] ['type'] = $files ['images'] ['type'] [$i]; 
      $_FILES ['images'] ['tmp_name'] = $files ['images'] ['tmp_name'] [$i]; 
      $_FILES ['images'] ['error'] = $files ['images'] ['error'] [$i]; 
      $_FILES ['images'] ['size'] = $files ['images'] ['size'] [$i]; 
      if ($this->upload->do_upload('images')){ 
       $upload_data = $this->upload->data(); 
       $file_name = $upload_data['file_name']; 
       $package->create_images(array('image_location' => $file_name)); 
      } 
     } 

     redirect('admin/packages/'); 
    } 
} 

뷰 코드 : 자사의

<div class="container"> 
    <?= form_open_multipart('admin/images/create/' . $this->uri->segment(4)) ?> 
    <div class="row"> 
     <div class="col-md-8 publish"> 
      <h4>Image Gallery</h4> 
      <div class="line"></div> 
      <ul> 
       <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script> 



        <div class="input-group control-group after-add-image"> 


         <label><input type="file" name="images[]"></label> 

         <div class="input-group-btn"> 
          <button class="btn btn-success add-image" type="button"><i class="glyphicon glyphicon-plus"></i> Add</button> 
         </div> 
        </div> 

       </ul> 

       <div class="line"></div> 

      <?= form_submit('', 'Submit', 'class="publish-btn"') ?> 

      <?= form_close()?> 
      <div class="clear-all"></div> 
      <!-- Copy Fields-These are the fields which we get through jquery and then add after the above input,--> 
      <div class="copy-field" style="display: none"> 
       <div class="control-group input-group" style="margin-top:10px"> 
        <label><label><input type="file" name="images[]"></label></label> 
        <div class="input-group-btn"> 
         <button class="btn btn-danger delete" type="button"><i class="glyphicon glyphicon-delete"></i> Remove</button> 
        </div> 
       </div> 
      </div> 
      <script type="text/javascript"> 
       $(document).ready(function() { 

        //here first get the contents of the div with name class copy-fields and add it to after "after-add-more" div class. 
        $(".add-image").click(function(){ 
         var html = $(".copy-field").html(); 
         $(".after-add-image").after(html); 
        }); 
//here it will remove the current value of the remove button which has been pressed 
        $("body").on("click",".delete",function(){ 
         $(this).parents(".control-group").remove(); 
        }); 

       }); 
      </script> 

을 받고 모든 이미지를 동적으로 업로드하여 디렉터리에 업로드 한 다음 데이터베이스에 경로를 저장합니다. 완료! CodeIgniter의 라이브러리를 업로드

the image for front end

0

을 선택하는 형태이다

+0

이 사진 –

+0

을 업로드하지 않습니다에 하나 개의 업로드 내장되어 업로드 경로가 파일을 업로드 해결 유효 –

+0

문제가 표시되지 않습니다 말한다. 문제는 컨트롤러가 아닌보기 파일에 있습니다. 이 양식을 사용하고 있기 때문에 양식이 함수에 응답하지 않습니다. 여러 이미지를 전송할 예정이므로 파일 배열을 사용하십시오. 내가 사용했을 때 작동했습니다 : 단일 파일. 하지만 동시에 여러 이미지를 제출해야합니다. 나는이 문제를 극복하기 위해 무엇을해야 하는가? 왜냐하면 나는 이미 어레이 메커니즘을 시도해 왔기 때문에 그 문제가 해결되지 않았기 때문이다. –

1
<?= form_open_multipart('admin/images/do_upload') ?> 

내가

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

를 추가 한 후 내가 라이브러리를 초기화하여 해결 잘못된 경로의 문제를 만들어 내 양식에 멀티를 추가하는 대신

<?= form_open('admin/images/do_upload') ?> 
0

의 위의 코드를 사용하여 라이브러리를로드하는이 줄 이후에.

$this->load->library('upload', $config); 

먼저 라이브러리를로드 한 다음 초기화하십시오. 하지만 여전히 선택의 문제가 해결되지 않았습니다 나는 다른 몇 가지 코드도 시도했습니다.

관련 문제