| 제목 | CI 연계해서 bootstrap 중에 ace templete 파일업로드 질문이 있습니다.... | ||
|---|---|---|---|
| 글쓴이 | 사짜 | 작성시각 | 2015/05/07 17:38:20 |
|
|
|||
현상은 이미지 파일들만 올라가고 zip 파일이나 docx 기타 파일들은 $_FILES 에 받아지질 않네요...
var $form = $(document);
//you can have multiple files, or a file input with "multiple" attribute
var file_input = $form.find('input[type=file]');
var upload_in_progress = false;
e.preventDefault();
var files = $(this).data('ace_input_files');
if( !files || files.length == 0 ) return false;//no files selected
var deferred ;
if( "FormData" in window ) {
var field_name = $(this).attr('name');
//for fields with "multiple" file support, field name should be something like `myfile[]`
var files = $(this).data('ace_input_files');
if(files && files.length > 0) {
for(var f = 0; f < files.length; f++) {
//formData_object.append(field_name, files[f]);
formData_object.append("file[]", files[f]);
console.log(formData_object);
console.log(files[f]);
}
}
//});
upload_in_progress = true;
file_input.ace_file_input('loading', true);
deferred = $.ajax({
url: "/base/uploader/upload",
type: "post",
processData: false,//important
contentType: false,//important
dataType: 'json',
data: formData_object
/**
,
xhr: function() {
var req = $.ajaxSettings.xhr();
if (req && req.upload) {
req.upload.addEventListener('progress', function(e) {
if(e.lengthComputable) {
var done = e.loaded || e.position, total = e.total || e.totalSize;
var percent = parseInt((done/total)*100) + '%';
//percentage of uploaded file
}
}, false);
}
return req;
},
beforeSend : function() {
},
success : function() {
}*/
})
}
JS 디버깅할때에는 files 에 분명히 파일이 쌓였고 formdata 변수에 쌓이면 내용이 안보이더라구요. 그 내용까지는 확인을 못해봤지만 이미지 파일일 경우에도 마찬가지라서 넘어갔습니다. 문제는 컨트롤러 부분인데... /base/uploader/upload 컨트롤러 소스에서는
public function upload () {
//our operation result including `status` and `message` which will be sent to browser
$result = array();
$file = $_FILES['file']; <-------- 이 부분입니다. 이미지일 경우 다 받아지는데 기타 파일들은 안받아지네요...
if( is_string($file['name']) ) {
//single file upload, file['name'], $file['type'] will be a string
$result[] = validateAndSave($file);
}
else if( is_array($file['name']) ) {
//multiple files uploaded
$file_count = count($file['name']);
//in PHP if you upload multiple files with `avatar[]` name, $file['name'], $file['type'], etc will be an array
for($i = 0; $i < $file_count; $i++) {
$file_info = array(
'name' => $file['name'][$i],
'type' => $file['type'][$i],
'size' => $file['size'][$i],
'tmp_name' => $file['tmp_name'][$i],
'error' => $file['error'][$i]
);
$result[] = $this->validateAndSave($file_info);
}
}
$upload_result = "";
for ($i=0; $i < count($result); $i++) {
//print_r($result[$i]);
$fileMap = array(
"web_path" => $result[$i][webpath],
"filename" => $result[$i][filename],
"realfilename" => $result[$i][realfilename],
"fileext" => $result[$i][extention],
);
$upload_result[$i][idx] = $this->fm->setFile($fileMap);
$upload_result[$i][status] = "OK";
}
$result = json_encode($upload_result);
print_r($result);
}
. 도무지 이유를 모르겠네요...js 폼데이터에서 넘길때 이미 상실이 된 상태인지, 아니면 PHP 부분에서 받는 부분이 문제인지도 감을 못잡겠네요... |
|||
| 다음글 | cookie의 물리적 size가 커서 header si... (2) | ||
| 이전글 | DB관련 연결 에러 문제입니다 ㅠ (3) | ||
| 없음 |