Guest User

Untitled

a guest
Jun 23rd, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.13 KB | None | 0 0
  1. <?php
  2. /*
  3. * Upload Class
  4. * Location: controllers/upload.php
  5. */
  6. class Upload extends Controller
  7. {
  8. function Upload()
  9. {
  10. parent::Controller();
  11. $this->load->helper('url');
  12. }
  13.  
  14. function index()
  15. {
  16. $this->template->load('page', 'content/uploadForm');
  17. //redirect('');
  18. }
  19.  
  20. function folder($folder_id)
  21. {
  22. if (!$this->dx_auth->is_logged_in()) {
  23. $this->dx_auth->deny_access('login');
  24. }
  25.  
  26. $this->load->model('axe_folder');
  27. if ($folder_id != 0) {
  28. if ($folder_id != '') {
  29. if ($this->axe_folder->check_folder($folder_id) == false) {
  30. show_error($this->axe_folder->get_error());
  31. return false;
  32. }
  33. }
  34. }
  35.  
  36. $data['folder_id'] = $folder_id;
  37.  
  38. $this->session->set_userdata('return_upload', 'content/uploadForm');
  39. $this->session->set_userdata('return_folder', true);
  40. $this->session->set_userdata('return_folder_id', $folder_id);
  41.  
  42. $this->template->load('page', 'content/uploadForm', $data);
  43. //redirect('');
  44. }
  45.  
  46. function application($app_id = '', $username = '', $password = '')
  47. {
  48.  
  49.  
  50. $uploadDirectory = 'uploads';
  51. $config['upload_path'] = $this->config->item('upload_folder');
  52. $config['allowed_types'] = $this->config->item('upload_types');
  53.  
  54. $config['max_size'] = '3072';
  55.  
  56. $this->load->library('upload', $config);
  57. $this->load->model('uploading');
  58. $this->uploading->uploadDirectory = $uploadDirectory;
  59.  
  60. $i = 0;
  61. foreach ($_FILES as $key => $value) {
  62. if (!empty($value['name'])) {
  63. if (!$this->upload->do_upload($key)) {
  64.  
  65. $error[$i]['message'] = $this->upload->error_msg;
  66. $error[$i]['filename'] = $value['name'];
  67.  
  68. $this->upload->error_msg = '';
  69.  
  70. $i++;
  71.  
  72. } else {
  73. $files[$key] = $this->upload->data();
  74. $imageData[$key] = $this->uploading->doProcess($files[$key], $folder_id);
  75. }
  76. }
  77. }
  78.  
  79.  
  80. }
  81.  
  82. /*
  83. * Actually do the uploading. duh.
  84. */
  85. function do_upload($folder_id = '')
  86. {
  87. if ($this->config->item('upload_public') == true || $this->dx_auth->
  88. is_logged_in() == true) {
  89.  
  90. $return_success = ($this->session->userdata('return_success') == '') ?
  91. 'content/uploadSuccess' : $this->session->userdata('return_success');
  92.  
  93. $return_upload = ($this->session->userdata('return_upload') == '') ?
  94. 'content/home' : $this->session->userdata('return_upload');
  95.  
  96. if ($folder_id != '') {
  97. if ($folder_id != 0) {
  98. $this->load->model('axe_folder');
  99. if ($this->axe_folder->check_folder($folder_id, $this->dx_auth->get_user_id()) == false) {
  100. show_error($this->axe_folder->get_error());
  101. return false;
  102. }
  103. }
  104. }
  105.  
  106. $uploadDirectory = 'uploads';
  107. $config['upload_path'] = $this->config->item('upload_folder');
  108. $config['allowed_types'] = $this->config->item('upload_types');
  109.  
  110. $config['max_size'] = '3072';
  111.  
  112. $this->load->library('upload', $config);
  113. $this->load->model('uploading');
  114. $this->uploading->uploadDirectory = $uploadDirectory;
  115.  
  116. $i = 0;
  117. $errors = false;
  118. $success = false;
  119. foreach ($_FILES as $key => $value) {
  120. if (!empty($value['name'])) {
  121. if (!$this->upload->do_upload($key)) {
  122.  
  123. $error[$i]['message'] = $this->upload->error_msg;
  124. $error[$i]['filename'] = $value['name'];
  125.  
  126. $this->upload->error_msg = '';
  127.  
  128. $i++;
  129. $errors = true;
  130.  
  131. } else {
  132. // Build a file array from all uploaded files
  133. $success = true;
  134. $files[$key] = $this->upload->data();
  135. $imageData[$key] = $this->uploading->doProcess($files[$key], $folder_id);
  136. }
  137. }
  138. }
  139.  
  140.  
  141. if (empty($files) and empty($error)) {
  142. $error = array('error' => 'You did not select a file to upload.');
  143. $error["folder_id"] = $folder_id;
  144. $this->template->load('page', $return_upload, $error);
  145. } else {
  146.  
  147. // okay, lets check to see if there were any errors.
  148.  
  149. if ($errors == true) {
  150. // there were
  151.  
  152. // was there any success?
  153. if ($success == true) {
  154. $templateData = array('upload_data' => $files, 'image_data' => $imageData,
  155. 'error_data' => $error);
  156.  
  157.  
  158. $this->template->load('page', 'content/uploadSuccess', $templateData);
  159. } else {
  160. $templateData = array('error' => $error);
  161.  
  162. $templateData["folder_id"] = $folder_id;
  163.  
  164.  
  165. $this->template->load('page', $return_upload, $templateData);
  166. }
  167.  
  168. } else {
  169. // there were not.
  170.  
  171. $templateData = array('upload_data' => $files, 'image_data' => $imageData);
  172.  
  173. if ($this->session->userdata('return_folder')) {
  174. $templateData["folder"] = $this->session->userdata('return_folder_id');
  175. }
  176.  
  177. $this->template->load('page', 'content/uploadSuccess', $templateData);
  178. }
  179.  
  180. }
  181. } else {
  182. show_error('Public uploading is turned off.');
  183. }
  184.  
  185. }
  186.  
  187. }
  188.  
  189. /* End of file upload.php */
  190. /* Location: ./system/application/controllers/upload.php */
Add Comment
Please, Sign In to add comment