You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
6.0 KiB

7 years ago
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /**************************************************************************************
  4. *
  5. * Class Upload
  6. *
  7. * 업로드 관련 컨트롤러
  8. *
  9. * @author Jang Seongeun <songwritersg@nexvation.com>
  10. * @date 2016.11.07
  11. *************************************************************************************/
  12. class Editor extends WB_Controller
  13. {
  14. function __construct()
  15. {
  16. parent::__construct();
  17. $this->load->library('upload');
  18. $this->theme = FALSE;
  19. }
  20. public function smarteditor($ed_nonce='')
  21. {
  22. make_dir(DIR_UPLOAD . DIRECTORY_SEPARATOR . "editor");
  23. $upload_path = DIR_UPLOAD . '/editor/' . date('Y') . '/' . date('m') . '/';
  24. if (isset($_FILES)
  25. && isset($_FILES['files'])
  26. && isset($_FILES['files']['name'])
  27. && isset($_FILES['files']['name'][0])) {
  28. $uploadconfig = array(
  29. 'upload_path' => "./" . $upload_path,
  30. 'allowed_types' => 'jpg|jpeg|png|gif',
  31. 'max_size' => 10 * 1024,
  32. 'encrypt_name' => true,
  33. );
  34. $this->upload->initialize($uploadconfig);
  35. $upload = isset($_FILES['files']) ? $_FILES['files'] : null;
  36. if( is_array( $upload['tmp_name'] ) ){
  37. $_FILES['userfile']['name'] = $upload['name'][0];
  38. $_FILES['userfile']['type'] = $upload['type'][0];
  39. $_FILES['userfile']['tmp_name'] = $upload['tmp_name'][0];
  40. $_FILES['userfile']['error'] = $upload['error'][0];
  41. $_FILES['userfile']['size'] = $upload['size'][0];
  42. } else {
  43. if($upload['type'] == "application/octet-stream"){
  44. $imageMime = getimagesize($upload['tmp_name']); // get temporary file REAL info
  45. $upload['type'] = $imageMime['mime']; //set in our array the correct mime
  46. }
  47. $_FILES['userfile']['name'] = $upload['name'];
  48. $_FILES['userfile']['type'] = $upload['type'];
  49. $_FILES['userfile']['tmp_name'] = $upload['tmp_name'];
  50. $_FILES['userfile']['error'] = $upload['error'];
  51. $_FILES['userfile']['size'] = $upload['size'];
  52. }
  53. if ($this->upload->do_upload()) {
  54. $filedata = $this->upload->data();
  55. $image_url = base_url(DIR_UPLOAD . '/editor/' . date('Y') . '/' . date('m') . '/' . element('file_name', $filedata));
  56. $info = new stdClass();
  57. $info->oriname = element('orig_name', $filedata);
  58. $info->name = element('file_name', $filedata);
  59. $info->size = intval(element('file_size', $filedata) * 1024);
  60. $info->type = 'image/' . str_replace('.', '', element('file_ext', $filedata));
  61. $info->url = $image_url;
  62. $info->width = element('image_width', $filedata) ? element('image_width', $filedata) : 0;
  63. $info->height = element('image_height', $filedata) ? element('image_height', $filedata) : 0;
  64. $return['files'][0] = $info;
  65. exit(json_encode($return));
  66. } else {
  67. exit($this->upload->display_errors());
  68. }
  69. } elseif ($this->input->get('file')) {
  70. unlink($upload_path . $this->input->get('file'));
  71. }
  72. }
  73. /**
  74. * CK 에디터를 통해 이미지를 업로드하는 컨트롤러입니다.
  75. */
  76. public function ckeditor($type="")
  77. {
  78. make_dir(DIR_UPLOAD . DIRECTORY_SEPARATOR . "editor");
  79. $upload_path = DIR_UPLOAD . '/editor/' . date('Y') . '/' . date('m') . '/';
  80. $uploadconfig = array(
  81. 'upload_path' => "./". $upload_path,
  82. 'allowed_types' => 'jpg|jpeg|png|gif',
  83. 'max_size' => 10 * 1024,
  84. 'encrypt_name' => true,
  85. );
  86. $CKEditorFuncNum = (int)$this->input->get('CKEditorFuncNum', null, 0);
  87. if (isset($_FILES)
  88. && isset($_FILES['upload'])
  89. && isset($_FILES['upload']['name'])) {
  90. $this->upload->initialize($uploadconfig);
  91. $_FILES['userfile']['name'] = $_FILES['upload']['name'];
  92. $_FILES['userfile']['type'] = $_FILES['upload']['type'];
  93. $_FILES['userfile']['tmp_name'] = $_FILES['upload']['tmp_name'];
  94. $_FILES['userfile']['error'] = $_FILES['upload']['error'];
  95. $_FILES['userfile']['size'] = $_FILES['upload']['size'];
  96. if ($this->upload->do_upload()) {
  97. $filedata = $this->upload->data();
  98. $image_url = base_url(DIR_UPLOAD . '/editor/' . date('Y') . '/' . date('m') . '/' . element('file_name', $filedata));
  99. if(empty($type))
  100. {
  101. exit ("<script>window.parent.CKEDITOR.tools.callFunction({$CKEditorFuncNum}, '{$image_url}', '업로드완료');</script>");
  102. }
  103. else if (strtolower($type) == 'json')
  104. {
  105. $return = array(
  106. "fileName" => $_FILES['upload']['name'],
  107. "uploaded" => 1,
  108. "url" => $image_url
  109. );
  110. exit(json_encode($return, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
  111. }
  112. } else {
  113. if(empty($type)) {
  114. echo $this->upload->display_errors();
  115. }
  116. else if (strtolower($type) == 'json')
  117. {
  118. $return = array(
  119. "fileName" => $_FILES['upload']['name'],
  120. "uploaded" => 0,
  121. "url" => "",
  122. "error" => array(
  123. "number" => 201,
  124. "message" => $this->upload->display_errors(' ',' ')
  125. )
  126. );
  127. exit(json_encode($return, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
  128. }
  129. }
  130. }
  131. }
  132. }