WEB언어/CodeIgniter
CodeIgniter Multiple file 업로드 하기
saltdoll
2018. 3. 9. 02:55
반응형
코드이그나이터 Multiple file 업로드
멀티 파일 업로드 <input type="file" name="upl_files[]" multiple /> 할 경우
|
출처: https://gist.github.com/zitoloco/1558423
참고:
(한글) 파일 업로드 Fiel Uploading Class http://www.ciboard.co.kr/user_guide/kr/libraries/file_uploading.html
(한글) 파일 업로드 File Uploading Class (2.1.0) http://codeigniter-kr.org/user_guide_2.1.0/libraries/file_uploading.html
I change upload method with images[]
according to @Denmark.
private function upload_files($path, $title, $files)
{
$config = array(
'upload_path' => $path,
'allowed_types' => 'jpg|gif|png',
'overwrite' => 1,
);
$this->load->library('upload', $config);
$images = array();
foreach ($files['name'] as $key => $image) {
$_FILES['images[]']['name']= $files['name'][$key];
$_FILES['images[]']['type']= $files['type'][$key];
$_FILES['images[]']['tmp_name']= $files['tmp_name'][$key];
$_FILES['images[]']['error']= $files['error'][$key];
$_FILES['images[]']['size']= $files['size'][$key];
$fileName = $title .'_'. $image;
$images[] = $fileName;
$config['file_name'] = $fileName;
$this->upload->initialize($config);
if ($this->upload->do_upload('images[]')) {
$this->upload->data();
} else {
return false;
}
}
return $images;
}
출처: https://stackoverflow.com/questions/20113832/multiple-files-upload-in-codeigniter
You can upload any number of files
$config['upload_path'] = 'upload/Main_category_product/';
$path=$config['upload_path'];
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '1024';
$config['max_width'] = '1920';
$config['max_height'] = '1280';
$this->load->library('upload', $config);
foreach ($_FILES as $key => $value) {
if (!empty($value['tmp_name']) && $value['size'] > 0) {
if (!$this->upload->do_upload($key)) {
$errors = $this->upload->display_errors();
flashMsg($errors);
} else {
// Code After Files Upload Success GOES HERE
}
}
}
And try using HTML like this:
<input type="file" name="file1" id="file_1" />
<input type="file" name="file2" id="file_2" />
<input type="file" name="file3" id="file_3" />
출처: https://stackoverflow.com/questions/9276756/codeigniter-multiple-file-upload
반응형