2012-12-16 3 views
0

나는 3 일간의 검색을 마치고 지쳤다. 누군가가 내게 말하면 이미지로 텍스트를 업로드하는 방법을 보여줄 수 있는가?codeigniter 양식

public function add() 
{ 

    $subject = array(
     'name' => $this->input->post('name'), 
     'lastname' => $this->input->post('lastname'), 
     'position' => $this->input->post('position'), 
     'pass_id' => $this->input->post('pass_id') 

     ); 


    $this->main_model->add($subject); 
    $this->index(); 
} 

와 모델 파일 :

my table: 

name -> varchar 
lastname -> varchar 
position -> varchar 
pass_id -> int 
image_url -> varchar 

이이 컨트롤러 파일입니다

<h2>Create</h2> 

<?php echo form_open('main/add'); ?> 
<p> 
    <label for="name">Name:</label> 
    <input type="text" name="name" id="name" /> 
</p> 

<p> 
    <label for="lastname">Lastname:</label> 
    <input type="text" name="lastname" id="lastname" /> 
</p> 

<p> 
    <label for="position">Position:</label> 
    <input type="text" name="position" id="position" /> 
</p> 


    <p> 
    <label for="name">Passport ID:</label> 
    <input type="text" name="pass_id" id="pass_id" /> 
</p> 

    <input type="file" name="userfile" size="20" /> 

    <input type="submit" value="Submit" /> 

<?php echo form_close(); ?> 

form_view의 파일에 이미지 URL을 업로드하는 방법

public function add($object) 
{ 
    $this->db->insert('stuf', $object); 
    return; 

} 

db.

저는 CI에서 초보자입니다. thanks

답변

0

을 테스트 한이 솔루션 :)에 대한

public function new_record() 
{ 

     $config['upload_path'] = './uploads/'; 
     $config['allowed_types'] = 'gif|jpg|png'; 
     $config['max_size'] = '100'; 
     $config['max_width'] = '1024'; 
     $config['max_height'] = '768'; 

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

     if (!$this->upload->do_upload('userfile')) 
     { 
       echo $this->upload->display_errors(); 
      } 
      else 
     { 
       $data = $this->upload->data(); 
       $full_path = 'uploads/' . $data['file_name']; 

      $subject = array(
       'name'  => $this->input->post('name'), 
       'lastname' => $this->input->post('lastname'), 
       'position' => $this->input->post('position'), 
       'pass_id' => $this->input->post('pass_id'), 
       'image_url' => $full_path 
      ); 


      $this->main_model->add($subject); 
      redirect('/main/index/', 'refresh'); 
     } 
0
$this->upload->data() 

업로드 한 파일과 관련된 모든 데이터가 들어있는 배열을 반환하는 도우미 함수입니다.

Array 
    (
     [file_name] => mypic.jpg 
     [file_type] => image/jpeg 
     [file_path] => /path/to/your/upload/ 
     [full_path] => /path/to/your/upload/jpg.jpg 
     [raw_name]  => mypic 
     [orig_name] => mypic.jpg 
     [client_name] => mypic.jpg 
     [file_ext]  => .jpg 
     [file_size] => 22.2 
     [is_image]  => 1 
     [image_width] => 800 
     [image_height] => 600 
     [image_type] => jpeg 
     [image_size_str] => width="800" height="200" 
) 

Source

2

사용하는 대신 form_open("main/add")form_open_multipart("main/add") 다음은 배열의 프로토 타입입니다.

그리고 컨트롤러 조금 수정 :

$this->load->library('upload'); // See File Uploading in Code Igniter Documentation 

$this->load->helper(array('form', 'url')); // See form, and url helper 

$my_path = "your_uploads_folder" 

$config['upload_path'] = './'. $my_path .'/'; 
$config['allowed_types'] = 'gif|jpg|png'; 
$config['max_size'] = '100'; 
$config['max_width']  = '1024'; 
$config['max_height'] = '768'; 

$this->upload->do_upload('userfile', $config); 

$subject = array(

    'url'  => $url . '/' . $my_path // Dont forget to create the table field 

    'name'  => $this->input->post('name'), 
    'lastname' => $this->input->post('lastname'), 
    'position' => $this->input->post('position'), 
    'pass_id' => $this->input->post('pass_id'), 
); 


$this->main_model->add($subject); 

redirect('/main/index/', 'refresh'); // Use redirect instead 

: 그것은 아직 확인

+0

덕분에 당신의 주의. 코드가 작동하지 않습니다. 코드를 코드화하려고합니다. 내가 할 수 있으면 여기에 게시 할 것입니다. – vkatsitadze

관련 문제