2013-06-21 2 views
0

저는 codeigniter와 협력 중이며 새로운 항목을 추가 할 수있는 양식이 있습니다.Codeigniter 이미지 업로드 및 내 폴더에 삽입

이 양식에는 이미지를 업로드하고 데이터베이스에 삽입 할 수있는 필드가 있습니다.

모두 내 데이터베이스에 삽입하는 것이 좋습니다.

내 질문은 내 폴더에 업로드 한 이미지를 어떻게 추가 할 수 있습니까?

경로 : 대부분의 다른처럼 업로드 클래스

초기화

function novo(){ 
    $this->load->helper(array('form', 'url')); 
    $this->load->library('form_validation'); 
    $this->form_validation->set_rules('banda', 'Banda', 'required'); 
    $this->form_validation->set_rules('data', 'Data', 'required'); 
    $this->form_validation->set_rules('hora_inicio', 'Hora In�cio', 'required|numeric'); 
    $this->form_validation->set_rules('hora_fim', 'Hora Fim', 'required|numeric'); 
    $this->form_validation->set_rules('morada', 'Morada', 'required'); 
    $this->form_validation->set_rules('preco', 'Pre�o', 'required|numeric'); 
    $this->form_validation->set_rules('aquisao_bilhetes', 'Aquisi��o de Bilhetes', 'required'); 
    $this->form_validation->set_rules('descricao', 'Observações', 'required'); 
    $this->form_validation->set_rules('image', 'Imagem', 'required|[image/jpeg|image/png]|file_path[../../imagens/banner/]'); 

    if (! $this->input->post()) 
    { 
     $this->load->view("concertForm"); 
    } 
    else 
    { 
     $dados=$this->input->post(); 
     $this->load->model("Dados_model"); 
     $results = $this->Dados_model->insere($dados); 
    } 
} 
+3

는 CI의 API와 관련된 질문은 파일 업로드 또는 처리 수 있나요 그런 다음, 업로드 코드 – user20232359723568423357842364

+0

를 게시 수동 http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html 읽기 업로드 된 파일을 DB에 "저장"하는 방법에 대해 확실하지 않습니까? –

+0

@MarcelloRomani : 내 질문에 폴더에 이미지를 추가하는 방법 .. 데이터베이스가 정상적으로 작동하기 때문에 – user2232273

답변

-1

어쩌면이 질문을 도울 수

1 : 여기 nameofproject/imagens/banner/

내 컨트롤러 CodeIgniter의 클래스, Upload cla SS는 사용하여 컨트롤러에 초기화됩니다 $ this->로드 -> 라이브러리 기능 :

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

이 설정 환경 설정 다른 라이브러리와 마찬가지로

, 당신은 할 수 있는지 제어 할 수 있습니다 기본 설정에 따라 업로드하십시오. 다음과 같은 기본 설정 위의 컨트롤러에서는 내장 :

$config['upload_path'] = './uploads/'; //you can change this set preferences for folder upload 

$config['allowed_types'] = 'gif|jpg|png'; 

$config['max_size'] = '100'; 

$config['max_width'] = '1024'; 

$config['max_height'] = '768'; 

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

// Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class: 

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

당신이 첵 수를이 User manual

+0

죄송합니다. 나는 온라인 설명서에서 copy-n-paste가 공정하다고 생각하지 않는다. –

+0

@MarcelloRomani 왜 이것이 공평하지 않습니까? –

+1

클릭 한 번으로 텍스트를 복사하는 이유는 무엇입니까? 포인터를 제공하기 만하면 OP는 거기에 대해 의문이 생기면 더 많은 질문을 읽고 다시 읽을 수 있습니다. –

0

당신이 (데이터베이스에서 이미지에 대한 참조를 저장하기 위해 찾고 계십니까 예 : 당신은 열이 파일 이름과 저장 위치 : myupload.jpg) 또는 실제로 이미지를 데이터베이스에 저장 하시겠습니까?

첫 번째 파일 인 경우 $this->upload->data() 도움말 기능을 사용하여 파일에 대한 정보를 얻고 싶을 것입니다.

건배

관련 문제