do_upload() public method

Perform the file upload
public do_upload ( string $field = 'userfile' ) : boolean
$field string
return boolean
Beispiel #1
0
 function do_upload($_FILES = '', $field = 'userfile')
 {
     if (empty($_FILES[$field])) {
         $this->set_error('upload_no_file_selected');
         return FALSE;
     } else {
         if (count($_FILES[$field]['name']) > 1) {
             foreach ($_FILES[$field]['name'] as $index => $name) {
                 if (!empty($name)) {
                     $this->do_xupload($_FILES, $field, $index);
                     $temp = parent::data();
                     $this->set_dataArray($temp, $index);
                 }
             }
             return true;
         } else {
             if ($field == 'proimg') {
                 $this->do_xupload($_FILES, $field);
                 $temp = parent::data();
                 $this->set_dataArray($temp, 0);
                 return true;
             } else {
                 parent::do_upload($_FILES, $field);
                 return parent::data();
             }
         }
     }
 }
 /**
  * @param string $file_name
  * @return boolean
  */
 public function upload($file_name)
 {
     $path = $this->_nuevoDirectorio();
     $config = array('upload_path' => $path, 'allowed_types' => 'gif|jpg|png|bmp|doc|docx|pdf|xls|xlsx|txt|ppt|pptx|csv', 'max_size' => '0', 'max_width' => '0', 'max_height' => '0');
     $this->upload = new CI_Upload($config);
     if (!$this->upload->do_upload($file_name)) {
         rmdir($path);
         $this->_error = $this->upload->display_errors();
         return false;
     } else {
         $data = $this->upload->data();
         $relative_path = str_replace(realpath(BASEPATH . "../"), "", realpath($data["full_path"]));
         $relative_path = substr($relative_path, 1, strlen($relative_path));
         $insert = array("arch_c_tamano" => $data["file_size"], "arch_c_nombre" => $relative_path, "arch_c_mime" => $data["file_type"], "arch_c_hash" => $this->_fileHash(), "arch_f_fecha" => DATE("Y-m-d H:i:s"), "usu_ia_id" => $this->session->userdata('session_idUsuario'));
         $this->_archivo_model->query()->insert($insert);
         return true;
     }
 }
 public function do_upload($field = 'userfile')
 {
     $ret = parent::do_upload($field);
     if ($ret) {
         $this->site_path = $this->system_upload_path . '/tmp/' . $this->file_name;
         $this->relative_path = 'tmp/' . $this->file_name;
     }
     return $ret;
 }
Beispiel #4
0
 public function do_upload($field = 'userfile')
 {
     if (!isset($_FILES[$field])) {
         return false;
     }
     // check if it's a multiple upload. if not then fall back to CI do_upload()
     if (!is_array($_FILES[$field]['name'])) {
         return parent::do_upload($field);
     } elseif (sizeof($_FILES[$field]['name']) == 1) {
         $files = $_FILES[$field];
         $_FILES[$field]['name'] = $files['name'][0];
         $_FILES[$field]['type'] = $files['type'][0];
         $_FILES[$field]['tmp_name'] = $files['tmp_name'][0];
         $_FILES[$field]['error'] = $files['error'][0];
         $_FILES[$field]['size'] = $files['size'][0];
         return $this->do_upload($field);
     } else {
         $files = $_FILES[$field];
         foreach ($files['name'] as $key => $value) {
             $_FILES[$field]['name'] = $files['name'][$key];
             $_FILES[$field]['type'] = $files['type'][$key];
             $_FILES[$field]['tmp_name'] = $files['tmp_name'][$key];
             $_FILES[$field]['error'] = $files['error'][$key];
             $_FILES[$field]['size'] = $files['size'][$key];
             if ($this->do_upload($field)) {
                 // if the upload was successfull add an element to the uploadedFiles array that contains the data regarding the uploaded file
                 $this->uploadedFiles[] = $this->data();
             } else {
                 // if the upload was unsuccessfull, set a temporary string that will contain the name of the file in question. The string will later be used by the modified display_errors() method
                 $this->tempString = 'File: ' . $_FILES[$field]['name'] . ' - Error: ';
                 // keep the errors in the multi_errors array
                 $this->multi_errors[] = $this->display_errors('', '');
             }
             // now we decide if we continue uploading depending on the "multi" key inside the configuration
             switch ($this->multi) {
                 case 'all':
                     if (sizeof($this->multi_errors) > 0 && sizeof($this->uploadedFiles > 0)) {
                         foreach ($this->uploadedFiles as $dataFile) {
                             if (file_exists($dataFile['full_path'])) {
                                 unlink($dataFile['full_path']);
                             }
                         }
                         break 2;
                     }
                     break;
                 case 'halt':
                     if (sizeof($this->multi_errors) > 0) {
                         break 2;
                     }
                     break;
                     //case 'ignore':
                 //case 'ignore':
                 default:
                     break;
             }
         }
         if (sizeof($this->multi_errors) > 0 && $this->multi == 'all') {
             return FALSE;
         }
         // at the end of the uploads, change the finished variable to true so that the class will know it finished it's main job
         $this->finished = TRUE;
         return TRUE;
     }
 }
Beispiel #5
0
 function do_upload($field = 'userfile')
 {
     $CI =& get_instance();
     if (!parent::do_upload($field)) {
         return FALSE;
     }
     $uploaded = $this->data();
     $_POST[$field] = $this->data_dir . '/' . $uploaded['file_name'];
     // copy original
     $dirname = 'data/' . $this->data_dir . '/original/';
     if (!file_exists($dirname)) {
         mkdir($dirname, 0777, true);
     }
     copy($uploaded['full_path'], 'data/' . $this->data_dir . '/original/' . $uploaded['file_name']);
     if ($this->is_watermarked) {
         $this->watermark($_POST);
     }
     foreach ($this->presets as $key => $preset) {
         $this->resize($_POST, $key);
     }
     unlink($this->data_dir . '/' . $uploaded['file_name']);
     return TRUE;
 }
Beispiel #6
0
 public static function upload($field, $id, $path, $config = array())
 {
     $CI =& get_instance();
     $ciConfig = $CI->config->item('utils');
     $config['upload_path'] = $ciConfig['file_dir'] . $path . '/';
     $config['allowed_types'] = '*';
     $config['file_name'] = self::getFileName($id, $path) . '.backup';
     $CI->load->library('upload');
     $upload = new CI_Upload($config);
     if (!$upload->do_upload($field)) {
         return $upload->display_errors('', '');
     } else {
         return TRUE;
     }
 }
Beispiel #7
0
 /**
  * 
  * @param string|integer $id (Primary Key)
  * @param string $name
  * @param string $folder (posts/images)
  * @return boolean
  */
 public static function upload($field, $id, $name, $folder, $config = array())
 {
     $CI =& get_instance();
     $ciConfig = $CI->config->item('utils');
     $config['upload_path'] = $path = $ciConfig['upload_dir'] . $folder . '/';
     $config['allowed_types'] = 'gif|jpg|png';
     $config['file_name'] = $fileName = self::getFileName($id, self::IMAGE_ORIGINAL, $name);
     $CI->load->library('upload');
     $CI->load->library('image_lib');
     $upload = new CI_Upload($config);
     if (!$upload->do_upload($field)) {
         return $upload->display_errors('', '');
     } else {
         $imageConfig = array('source_image' => $path . $fileName);
         foreach (array(self::IMAGE_LARGE, self::IMAGE_MEDIUM, self::IMAGE_SMALL) as $size) {
             $imageConfig['new_image'] = $path . self::getFileName($id, $size, $name);
             //                list($imageConfig['width'], $imageConfig['height']) = explode('x', $ciConfig['image'][strtolower($size)]);
             list($imageConfig['width']) = explode('x', $ciConfig['image'][strtolower($size)]);
             $image = new CI_Image_lib();
             $image->initialize($imageConfig);
             $image->resize();
             $image->clear();
         }
         $imageConfig['new_image'] = $path . self::getFileName($id, self::IMAGE_THUMB, $name);
         list($imageConfig['width'], $imageConfig['height']) = explode('x', $ciConfig['image'][strtolower(self::IMAGE_THUMB)]);
         $imageConfig['maintain_ratio'] = FALSE;
         $image = new CI_Image_lib();
         $image->initialize($imageConfig);
         $image->resize();
         $image->clear();
         return TRUE;
     }
 }
Beispiel #8
0
 function submit($submit)
 {
     try {
         if ($submit == 'generate_express') {
             $article_ids = preg_split('/,[\\s]*/', $this->input->post('articles'));
             if (!is_array($article_ids)) {
                 $this->output->message('文章id解析错误');
                 throw new Exception();
             }
             $config['upload_path'] = './images/mail/express';
             $config['encrypt_name'] = true;
             $config['allowed_types'] = 'jpg';
             $this->load->library('upload', $config);
             if (!$this->upload->do_upload('header')) {
                 $this->output->message($this->upload->display_errors(), 'warning');
                 throw new Exception();
             }
             $header = $this->upload->data();
             $config['allowed_types'] = 'pdf';
             $config['encrypt_name'] = false;
             $Attachment = new CI_Upload($config);
             if (!$Attachment->do_upload('attachment')) {
                 $this->output->message($Attachment->display_errors(), 'warning');
                 //throw new Exception;
             }
             //$attachment=$Attachment->data();
             $articles = $this->mail->getArticles('star', $article_ids);
             $this->load->addViewData('title', $this->input->post('title'));
             $this->load->addViewData('articles', $articles);
             $this->load->addViewData('header_img', $header['file_name']);
             $mail_html = $this->load->view('mail/express_template', true);
             $this->user->setConfig('mail/express/mail_html', $mail_html);
             $this->user->setConfig('mail/express/title', '星瀚律师 - ' . $this->input->post('title'));
             //$this->session->set_userdata('mail/express/attachment','./images/mail/express/'.$attachment['file_name']);
             $this->output->setData($mail_html, 'preview', 'html', '#express-preview');
         }
         if ($submit == 'send_express') {
             if (!$this->config->user_item('mail/express/mail_html')) {
                 $this->output->message('还没有生成期刊');
                 throw new Exception();
             }
             if (!$this->input->post('client-emails')) {
                 $client_emails = $this->config->user_item('mail/express/receivers');
             } else {
                 $client_emails = preg_split('/,[\\s]*/', $this->input->post('client-emails'));
                 $this->user->setConfig('mail/express/receivers', json_encode($client_emails));
             }
             $this->load->library('email');
             $config = array('protocol' => 'smtp', 'smtp_host' => 'smtp.exmail.qq.com', 'smtp_user' => '*****@*****.**', 'smtp_pass' => '1218xinghan', 'mailtype' => 'html', 'crlf' => "\r\n", 'newline' => "\r\n");
             $this->email->initialize($config);
             $this->email->from('*****@*****.**', '星瀚律师');
             $this->email->subject($this->config->user_item('mail/express/title'));
             $this->email->message($this->config->user_item('mail/express/mail_html'));
             //$this->email->attach($this->session->userdata('mail/express/attachment'));
             if ($this->config->user_item('mail/express/send_progress') < count($this->config->user_item('mail/express/receivers'))) {
                 $receivers = $this->config->user_item('mail/express/receivers');
                 $receiver = $receivers[$this->config->user_item('mail/express/send_progress')];
                 if ($this->email->to($receiver)) {
                     $delivery_status = '';
                 } else {
                     $delivery_status = '(x)';
                 }
                 $this->output->setData($receiver . ' ', 'receiver', 'html', '#delivery-status', 'append');
                 $this->email->send();
                 sleep(3);
                 $this->user->setConfig('mail/express/send_progress', $this->config->user_item('mail/express/send_progress') + 1);
                 $this->output->setData('$(\'[name="submit[send_express]"]:first\').trigger(\'click\')', 'script', 'script');
             } else {
                 $this->output->message('发送完毕');
             }
         }
         if ($submit == 'download') {
             $this->output->as_ajax = false;
             $this->load->model('document_model', 'document');
             $this->document->exportHead('express.html');
             $this->output->set_output($this->config->user_item('mail/express/mail_html'));
         }
         $this->output->status = 'success';
     } catch (Exception $e) {
         $this->output->status = 'fail';
     }
 }