Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Upload Class
- * Location: controllers/upload.php
- */
- class Upload extends Controller
- {
- function Upload()
- {
- parent::Controller();
- $this->load->helper('url');
- }
- function index()
- {
- $this->template->load('page', 'content/uploadForm');
- //redirect('');
- }
- function folder($folder_id)
- {
- if (!$this->dx_auth->is_logged_in()) {
- $this->dx_auth->deny_access('login');
- }
- $this->load->model('axe_folder');
- if ($folder_id != 0) {
- if ($folder_id != '') {
- if ($this->axe_folder->check_folder($folder_id) == false) {
- show_error($this->axe_folder->get_error());
- return false;
- }
- }
- }
- $data['folder_id'] = $folder_id;
- $this->session->set_userdata('return_upload', 'content/uploadForm');
- $this->session->set_userdata('return_folder', true);
- $this->session->set_userdata('return_folder_id', $folder_id);
- $this->template->load('page', 'content/uploadForm', $data);
- //redirect('');
- }
- function application($app_id = '', $username = '', $password = '')
- {
- $uploadDirectory = 'uploads';
- $config['upload_path'] = $this->config->item('upload_folder');
- $config['allowed_types'] = $this->config->item('upload_types');
- $config['max_size'] = '3072';
- $this->load->library('upload', $config);
- $this->load->model('uploading');
- $this->uploading->uploadDirectory = $uploadDirectory;
- $i = 0;
- foreach ($_FILES as $key => $value) {
- if (!empty($value['name'])) {
- if (!$this->upload->do_upload($key)) {
- $error[$i]['message'] = $this->upload->error_msg;
- $error[$i]['filename'] = $value['name'];
- $this->upload->error_msg = '';
- $i++;
- } else {
- $files[$key] = $this->upload->data();
- $imageData[$key] = $this->uploading->doProcess($files[$key], $folder_id);
- }
- }
- }
- }
- /*
- * Actually do the uploading. duh.
- */
- function do_upload($folder_id = '')
- {
- if ($this->config->item('upload_public') == true || $this->dx_auth->
- is_logged_in() == true) {
- $return_success = ($this->session->userdata('return_success') == '') ?
- 'content/uploadSuccess' : $this->session->userdata('return_success');
- $return_upload = ($this->session->userdata('return_upload') == '') ?
- 'content/home' : $this->session->userdata('return_upload');
- if ($folder_id != '') {
- if ($folder_id != 0) {
- $this->load->model('axe_folder');
- if ($this->axe_folder->check_folder($folder_id, $this->dx_auth->get_user_id()) == false) {
- show_error($this->axe_folder->get_error());
- return false;
- }
- }
- }
- $uploadDirectory = 'uploads';
- $config['upload_path'] = $this->config->item('upload_folder');
- $config['allowed_types'] = $this->config->item('upload_types');
- $config['max_size'] = '3072';
- $this->load->library('upload', $config);
- $this->load->model('uploading');
- $this->uploading->uploadDirectory = $uploadDirectory;
- $i = 0;
- $errors = false;
- $success = false;
- foreach ($_FILES as $key => $value) {
- if (!empty($value['name'])) {
- if (!$this->upload->do_upload($key)) {
- $error[$i]['message'] = $this->upload->error_msg;
- $error[$i]['filename'] = $value['name'];
- $this->upload->error_msg = '';
- $i++;
- $errors = true;
- } else {
- // Build a file array from all uploaded files
- $success = true;
- $files[$key] = $this->upload->data();
- $imageData[$key] = $this->uploading->doProcess($files[$key], $folder_id);
- }
- }
- }
- if (empty($files) and empty($error)) {
- $error = array('error' => 'You did not select a file to upload.');
- $error["folder_id"] = $folder_id;
- $this->template->load('page', $return_upload, $error);
- } else {
- // okay, lets check to see if there were any errors.
- if ($errors == true) {
- // there were
- // was there any success?
- if ($success == true) {
- $templateData = array('upload_data' => $files, 'image_data' => $imageData,
- 'error_data' => $error);
- $this->template->load('page', 'content/uploadSuccess', $templateData);
- } else {
- $templateData = array('error' => $error);
- $templateData["folder_id"] = $folder_id;
- $this->template->load('page', $return_upload, $templateData);
- }
- } else {
- // there were not.
- $templateData = array('upload_data' => $files, 'image_data' => $imageData);
- if ($this->session->userdata('return_folder')) {
- $templateData["folder"] = $this->session->userdata('return_folder_id');
- }
- $this->template->load('page', 'content/uploadSuccess', $templateData);
- }
- }
- } else {
- show_error('Public uploading is turned off.');
- }
- }
- }
- /* End of file upload.php */
- /* Location: ./system/application/controllers/upload.php */
Add Comment
Please, Sign In to add comment