2017-02-28 1 views
0

다른 입력과 파일 업로드 입력을 포함하는 양식이 있습니다. 사용자가 이미지를 업로드하고 업로드하고 싶지만 업로드하고 싶지 않은 경우 사용자를 원합니다. 오류를주지 마십시오.Codeigniter 업로드 이미지 선택

if($_POST){   
    $config['upload_path']   = 'images/tmp'; 
    $config['allowed_types']  = 'gif|jpg|png'; 
    $config['max_size']    = 2048; 
    $config['min_width']   = 480; 
    $config['min_height']   = 360; 

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

    if (!$this->upload->do_upload('userfile')) { 
     $error = array('error' => $this->upload->display_errors()); 
     //Sending this $error to view and if a user didnt upload image and just filled 
     //the other inputs it shows error. but i dont want that. 
    } else { } 
} else { 
    redirect(site_url()); 
} 

답변

0

오른쪽 트랙에 있습니다. 그냥 당신은 아래와 같은 파일을 볼 수 있도록 $ 오류를 보낼 수 있습니다이 줄을

$error = array('error' => $this->upload->display_errors());

을 삭제 또는 의견 :

$this->load->view('upload_form', $error);

그래서 파일을 볼 수 있도록 값을 보내지 마십시오. 이미지가 성공적으로 아래에 업로드 할 때 그냥보기 전화 :

 

      if (! $this->upload->do_upload('userfile')) 
      { 

       // $error = array('error' => $this->upload->display_errors()); 
       /*Delete or comment this line. Do your other stuff here if image not uploaded.*/ 

      }else{ 
        $data = array('upload_data' => $this->upload->data()); 
        $this->load->view('upload_success', $data); 
        /* This is example. You can do anything on successfully image upload.*/ 
      } 

을 당신은 내가 오류를주지에 업로드 클래스를 변경 내 문제를 해결 https://www.codeigniter.com/userguide3/libraries/file_uploading.html

+0

그래, 괜찮아요. 그러나 허용되는 유형과 같은 다른 오류는 어때요? 나는 단지 이미지가 업로드 된 오류가 아니라는 것을 보여주고 싶다. – codeigniter

0
$config['upload_path']   = 'images/tmp'; 
    $config['allowed_types']  = 'gif|jpg|png'; 
    $config['max_size']    = 2048; 
    $config['min_width']   = 480; 
    $config['min_height']   = 360;  
    $this->load->library('upload', $config); 
     //$rand_str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
     // $filename=md5(str_shuffle($rand_str.mt_rand())); 
     // $config['file_name']=$filename; 

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

      if ($this->upload->do_upload('userfile')) 
      { 
        //$data = array('upload_data' => $this->upload->data()); 
        // $data["filename"]=$filename; 
        // $data["ad_id"]=$lid; 

        // $data["filename"]=$rand_name; 
        // $this->Ads_model->insert_image($data); 



      } 
0

CodeIgniter의 설명서를 참조 할 수 있습니다. 나는 "선택된 파일 없음"을 포함한 줄을 주석 처리했다.

관련 문제