2013-12-14 1 views
0

입니다. Codeigniter 및 Ajax가있는 양식에서 이미지를 업로드 해보십시오.파일 및 공통 데이터 형식이

<?php 
$config = array('class' => "small-12 columns no-left-margins",'id'=>"form_$i", 'enctype'=>"multipart/form-data"); 
echo form_open_multipart('', $config); 
?> 
<!-- file, text, and text area inputs --> 
<?php 
echo form_close(); 
?> 
<a href="#" class="button tiny right" id="submit" value="upload">Guardar</a> 

Ajax 요청은 다음과 같습니다 : 나는 다음 형식 구조를 만들

$("form").submit(function(e){ 
    e.preventDefault(); 
    var datos = $(this).serializeArray(); 
    $.ajax({ 
     url: 'guardarNuevoProducto', 
     type: 'POST', 
     data: datos 
    }); 

}); 

그리고 컨트롤러 액션 코드는 다음과 같습니다

// uploadPicture_rules is the index of the $config array that contains the picture //validation rules 
$picRules = $this->config->item('uploadPicture_rules'); 

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

if(!$this->upload->do_upload()){ 
    echo json_encode(array('st'=>0, 'msg' => $this->upload->display_errors())); 
}else{ 
    echo json_encode(array('st'=>0, 'msg' => 'Successfully Submiited')); 
} 

그리고 다음 파일 업로드 유효성 검사 규칙이 있습니다 :

$config['uploadPicture_rules'] = Array(
    'allowed_types' => 'gif|jpg|png', 
    'max_size' =>'100', 
    'upload_path' => '/assets' 
); 

al L 양식 값을 제대로 확인되지만, file_uploader는 말한다 :

{ "성": 0, "MSG": "당신은 업로드 할 파일을 선택하지 않았습니다."}

어떤 아이디어? . 나는 잘못된 congiruation가?

답변

0

form_open() 변경 전 변경했다,() 회신

+0

감사 form_open_multipart,하지만 아약스 요청은 같은 오류를 반환합니다. – ramiromd

+0

http://stackoverflow.com/questions/2320069/jquery-ajax-file-upload 도움이 될 수 있습니다. –