Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @Author: juliarnasution
- * @Date: 2020-03-21 17:03:07
- * @Last Modified by: Dell
- * @Last Modified time: 2020-03-21 17:13:49
- */
- class Dokumen extends CI_Controller
- {
- public function uploadfile()
- {
- if(array_key_exists('file1',$_FILES) && $_FILES['file1']['size']>0){
- $file1 = $this->upload_file1('file1');//upload $)FILES['file1'];
- if ($file1['result']==false) {
- echo "error : gagal di upload";
- }else{
- echo "file1 berhasil di upload";
- }
- }
- if(array_key_exists('file2',$_FILES) && $_FILES['file2']['size']>0){
- $file2 = $this->upload_file2('file2');//upload $)FILES['file2'];
- if ($file2['result']==false) {
- echo "error : gagal di upload";
- }else{
- echo "file2 berhasil di upload";
- }
- }
- }
- public function upload_file1($data)
- {
- $config['upload_path'] = './files' ;
- $config['allowed_types'] = 'jpg|jpeg|png';
- $config['max_size'] = '400';
- $config['remove_space'] = TRUE;
- $config['file_name'] = $data;
- $this->load->library('upload', $config,'file1');//membuat object dengan nama file1
- $this->file1->initialize($config);
- if (!$this->file1->do_upload($data)){
- return array('result'=>FALSE,'file'=>'','error' => $this->file1->display_errors());
- }
- else{
- return array('result'=>TRUE,'file'=>$this->file1->data(),'upload_data' => $this->file1->data());
- }
- }
- public function upload_file2($data)
- {
- $config['upload_path'] = './files' ;
- $config['allowed_types'] = 'jpg|jpeg|png';
- $config['max_size'] = '400';
- $config['remove_space'] = TRUE;
- $config['file_name'] = $data;
- $this->load->library('upload', $config,'file2');//membuat object dengan nama file2
- $this->file2->initialize($config);
- if (!$this->file2->do_upload($data)){
- return array('result'=>FALSE,'file'=>'','error' => $this->file2->display_errors());
- }
- else{
- return array('result'=>TRUE,'file'=>$this->file2->data(),'upload_data' => $this->file2->data());
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement