/** * 미디어 파일을 업로드한다. */ public function upload() { global $wpdb; $this->board_id = intval($this->board_id); $this->media_group = addslashes($this->media_group); if ($this->board_id && $this->media_group) { $upload_dir = wp_upload_dir(); $attach_store_path = str_replace(KBOARD_WORDPRESS_ROOT, '', $upload_dir['basedir']) . "/kboard_attached/{$this->board_id}/" . current_time('Ym') . '/'; $file = new KBFileHandler(); $file->setPath($attach_store_path); $upload = $file->upload('kboard_media_file'); $file_name = addslashes($upload['original_name']); $file_path = addslashes($upload['path'] . $upload['stored_name']); if ($file_name) { $date = current_time('YmdHis'); $wpdb->query("INSERT INTO `{$wpdb->prefix}kboard_meida` (`media_group`, `date`, `file_path`, `file_name`) VALUE ('{$this->media_group}', '{$date}', '{$file_path}', '{$file_name}')"); } } }
/** * 썸네일을 등록한다. * @param int $uid */ public function setThumbnail($uid) { global $wpdb; if (!$this->thumbnail_store_path) { die(__('No upload path. Please enter board ID and initialize.', 'kboard')); } if ($_FILES['thumbnail']['tmp_name']) { $file = new KBFileHandler(); $file->setPath($this->thumbnail_store_path); $upload = $file->upload('thumbnail'); $original_name = addslashes($upload['original_name']); $file = addslashes($upload['path'] . $upload['stored_name']); if ($original_name) { $this->removeThumbnail($uid); $wpdb->query("UPDATE `{$wpdb->prefix}kboard_board_content` SET `thumbnail_file`='{$file}', `thumbnail_name`='{$original_name}' WHERE `uid`='{$uid}'"); } } }
/** * 썸네일을 등록한다. */ public function setThumbnail() { global $wpdb; if (!$this->thumbnail_store_path) { die(__('No upload path. Please enter board ID and initialize.', 'kboard')); } if ($this->uid && $_FILES['thumbnail']['tmp_name']) { $file = new KBFileHandler(); $file->setPath($this->thumbnail_store_path); $upload = $file->upload('thumbnail'); $original_name = esc_sql($upload['original_name']); $file = esc_sql($upload['path'] . $upload['stored_name']); if ($original_name) { // 업로드된 원본 이미지 크기를 줄인다. $upload_dir = wp_upload_dir(); $file_path = explode('/wp-content/uploads', $upload['path'] . $upload['stored_name']); $file_path = strtolower($upload_dir['basedir'] . end($file_path)); $image_editor = wp_get_image_editor($file_path); if (!is_wp_error($image_editor)) { $thumbnail_size = apply_filters('kboard_thumbnail_size', array(1024, 1024)); $image_editor->resize($thumbnail_size[0], $thumbnail_size[0]); $image_editor->save($file_path); } $this->removeThumbnail(false); $wpdb->query("UPDATE `{$wpdb->prefix}kboard_board_content` SET `thumbnail_file`='{$file}', `thumbnail_name`='{$original_name}' WHERE `uid`='{$this->uid}'"); } } }