나는 이것에 절대적으로 얽매여 있습니다 ... 관련된 모든 stackoverflow 게시물을 확인했는데 아무런 도움이되지 않았습니다. Codeigniter에서 Phil의 REST Server/Client 설정을 사용하고 일반 항목을 삽입 할 수 있지만 여러 이미지 (실제로는 단일 이미지)를 업로드 할 수는 없습니다.Codeigniter REST 복수 이미지 업로드
정말 REST 부분을 디버깅하는 방법을 배울 수 없으며 아무 것도 반환하지 않습니다.
function multifile_array()
{
if(count($_FILES) == 0)
return;
$files = array();
$all_files = $_FILES['files']['name'];
$i = 0;
foreach ($all_files as $filename) {
$files[++$i]['name'] = $filename;
$files[$i]['type'] = current($_FILES['files']['type']);
next($_FILES['files']['type']);
$files[$i]['tmp_name'] = current($_FILES['files']['tmp_name']);
next($_FILES['files']['tmp_name']);
$files[$i]['error'] = current($_FILES['files']['error']);
next($_FILES['files']['error']);
$files[$i]['size'] = current($_FILES['files']['size']);
next($_FILES['files']['size']);
}
$_FILES = $files;
}
을이 기능 :
Array
(
[1] => Array
(
[name] => sideshows.jpg
[type] => image/jpeg
[tmp_name] => /Applications/MAMP/tmp/php/phppYycdA
[error] => 0
[size] => 967656
)
[2] => Array
(
[name] => the-beer-scale.jpg
[type] => image/jpeg
[tmp_name] => /Applications/MAMP/tmp/php/phpCsiunQ
[error] => 0
[size] => 742219
)
[3] => Array
(
[name] => the-little-lace.jpg
[type] => image/jpeg
[tmp_name] => /Applications/MAMP/tmp/php/phpXjT7WL
[error] => 0
[size] => 939963
)
[4] => Array
(
[name] => varrstoen-australia.jpg
[type] => image/jpeg
[tmp_name] => /Applications/MAMP/tmp/php/phpcHrJXe
[error] => 0
[size] => 2204400
)
)
은 내가 여러 파일 업로드를 분류하는 것으로,이 도우미 방법을 사용하고 있습니다 :
내가보기에서 들어오는이 배열이 API 컨트롤러 내에서 호출 중입니다.
public function my_file_upload_post() {
if(! $this->post('submit')) {
$this->response(NULL, 400);
}
$data = $this->post('data');
multifile_array();
$foldername = './uploads/' . $this->post('property_id');
if(!file_exists($foldername) && !is_dir($foldername)) {
mkdir($foldername, 0750, true);
}
$config['upload_path'] = $foldername;
$config['allowed_types'] = 'gif|jpg|png|doc|docx|pdf|xlsx|xls|txt';
$config['max_size'] = '10240';
$this->load->library('upload', $config);
foreach ($data as $file => $file_data) {
$this->upload->do_upload($file);
//echo '<pre>';
//print_r($this->upload->data());
//echo '</pre>';
}
if (! $this->upload->do_upload()) {
return $this->response(array('error' => strip_tags($this->upload->display_errors())), 404);
} else {
$upload = $this->upload->data();
return $this->response($upload, 200);
}
}
내 코드를 공유하게되어 기쁩니다. 걱정할 필요없이 여러 파일을 업로드 할 수 있었지만 API를 사용하여 외부 웹 사이트, 내부 또는 iPhone에서 호출 할 수있었습니다. 도움을 주시면 감사하겠습니다.
건배
업데이트 : 여기
이 API 컨트롤러의 코드입니다 :
function upload_post() {
$foldername = './uploads/' . $this->post('property_id');
if(!file_exists($foldername) && !is_dir($foldername)) {
mkdir($foldername, 0750, true);
}
$config['upload_path'] = $foldername;
$config['allowed_types'] = 'gif|jpg|png|doc|docx|pdf|xlsx|xls|txt';
$config['max_size'] = '10240';
$this->load->library('upload', $config);
if (! $this->upload->do_upload())
{
//return $this->response(array('error' => strip_tags($this->upload->display_errors())), 404);
return $this->response(array('error' => var_export($this->post('file'), true)), 404);
}
else
{
$data = array('upload_data' => $this->upload->data());
return $this->response(array('error' => $data['upload_data']), 404);
}
return $this->response(array('success' => 'successfully uploaded'), 200);
}
이 양식에서 API로 직접 이동하는 경우 작동하지만 브라우저에서 사용자 이름과 암호를 입력해야합니다. 컨트롤러를 통해 이것을 실행하면 이미지를 찾을 수 없습니다.