2012-12-29 3 views
0

모든 것이 정상이지만 업로드 폴더를 열면 이미지가 없습니다.사진이 codeigniter에 업로드되었습니다.

여기에 컨트롤러 "admin_news"가 있습니다. localhost/site/asset/upload에 이미지 파일을 업로드하려고합니다. 그러나 제출을 클릭하면 정보 (제목, 뉴스 및 카테고리) 만 데이터베이스에 저장되지만 파일은 업로드되지 않습니다.

function __construct() 
{ 
    parent::__construct(); 
    $this->load->helper(array('form', 'html', 'file')); 
    $config['upload_path'] = base_url('asset/upload/'); 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $this->load->library('upload', $config); 
} 


public function add_news(){ 
    $this->load->helper('form'); 
    $this->load->model('AddNews'); 
    $this->load->view('templates/header', $data); 
    $this->load->view('admin/add_news'); 
    $this->load->view('templates/footer'); 
    if($this->input->post('submit')){ 
     if ($this->upload->do_upload('image')) 
     { 
      $this->upload->initialize($config); 
      $this->upload->data(); 
     } 
     $this->AddNews->entry_insert(); 
     redirect("admin_news/index"); 
    } 
} 

뷰에만 있습니다

 <?php echo form_open_multipart(''); ?> 
    <input type="text" name="title" value="Title..." onfocus="this.value=''" /><br /> 
    <input type="file" name="image" /><br /> 

....

+0

나는 컨트롤러/함수 이름이 열린 태그 형태로 없다고 생각한다. '' –

+0

그것은 동일한 형태의 비 코즈가 아닙니다. 제목, 뉴스 및 카테고리가 datebase 오른쪽으로 들어갑니다. – Ant

답변

1

이것은 URL 안 : 그것은 어딘가에 경로를해야

$config['upload_path'] = base_url('asset/upload/'); 

당신의 서버, 전체 절대 경로 또는 상대 경로 (Codeigniter의 모든 경로는 index.php와 관련이 있습니다). 이들의

사용 중 하나를

// Full path 
$config['upload_path'] = FCPATH.'asset/upload/'; 

// Relative 
$config['upload_path'] = './asset/upload/'; 

한가지 더 :

난 당신의 코드에서 생각
if ($this->upload->do_upload('image')) 
{ 
    // You don't need this, and besides $config is undefined 
    // $this->upload->initialize($config); 

    // You don't seem to be doing anything with this? 
    $this->upload->data(); 

    // Move this here in case upload fails 
    $this->AddNews->entry_insert(); 
    redirect("admin_news/index"); 
} 
// Make sure to show errors 
else 
{ 
    echo $this->upload->display_errors(); 
} 
+0

덕분에 모든 것이 괜찮습니다. 이제 – Ant

+0

@ 개미, 실제로 어떻게 만들었습니까? – newday

0

, 문제는이 선언되는 구성 do_upload 방법 후

if ($this->upload->do_upload('image')) 
     { 
      $this->upload->initialize($config); 
      $this->upload->data(); 
     } 

구성을 사용하기 전에 구성을 초기화해야합니다. 나는 그것이 문제라고 생각한다. 그래서 당신은 do_upload 메쏘드 앞에 설정을해야만한다.

관련 문제