/** * upload file db update * tempFiles 테이블에 있는 임시파일들 목록을 files 테이블에 옮기고, 썸네일으로 사용하는 첨부파일 번호를 리턴한다. * * @param array $post $_POST * @param int $art_srl 글을 등록하고 바로 가져온 srl번호 * @param int $thum_srl 썸네일 srl번호 * @return int 바뀐 썸네일 srl번호 */ function fileUpload($post, $art_srl, $thum_srl) { $thumnail_srl = null; if ($post['addQueue']) { $queue = explode(',', $post['addQueue']); foreach ($queue as $k => $v) { if (!$v) { continue; } $tmpFile = Spawn::item(array('table' => Spawn::getTableName('file_tmp'), 'where' => 'srl=' . (int) $v)); if (count($tmpFile)) { // insert file $result = Spawn::insert(array('table' => Spawn::getTableName('file'), 'data' => array('srl' => null, 'article_srl' => $art_srl, 'name' => $tmpFile['name'], 'loc' => $tmpFile['loc'], 'type' => $tmpFile['type'], 'size' => $tmpFile['size'], 'regdate' => date("YmdHis")))); // set thumnail srl if ($tmpFile['srl'] == $thum_srl) { $thumnail_srl = Spawn::getLastIdx(); } // remove tmp file $result = Spawn::delete(array('table' => Spawn::getTableName('file_tmp'), 'where' => 'srl=' . (int) $v)); } } } return $thumnail_srl ? $thumnail_srl : $thum_srl; }
<?php if (!defined('__GOOSE__')) { exit; } // check user if (!$this->isAdmin) { return array('state' => 'error', 'action' => 'back', 'message' => '권한이 없습니다.'); } // check post $errorValue = Util::checkExistValue($post, array('article_srl')); if ($errorValue) { return array('state' => 'error', 'action' => 'back', 'message' => "[{$errorValue}]값이 없습니다."); } // remove data $result = Spawn::delete(array('table' => Spawn::getTableName($this->name), 'where' => 'srl=' . $post['article_srl'])); if ($result != 'success') { return array('state' => 'error', 'action' => 'back', 'message' => 'Fail execution database'); } // load module $file = Module::load('file'); // get srls $data = $file->getItems(array('field' => 'srl', 'where' => 'article_srl=' . $post['article_srl'])); $files = $data['state'] == 'success' ? $data['data'] : null; if ($files) { $srls = array(); foreach ($files as $k => $v) { $srls[] = (int) $v['srl']; } $result = $file->actRemoveFile($srls, 'file'); }
if ($post['delete_article']) { $file = Module::load('file'); // remove attach files $articles = Spawn::items(array('table' => Spawn::getTableName('article'), 'field' => 'srl', 'where' => 'nest_srl=' . (int) $post['nest_srl'])); $file_srls = array(); foreach ($articles as $k => $v) { $data = $file->getItems(array('field' => 'srl', 'where' => 'article_srl=' . (int) $v['srl'])); if ($data['state'] == 'success') { foreach ($data['data'] as $k2 => $v2) { if ($v2['srl']) { $file_srls[] = (int) $v2['srl']; } } } } $file->actRemoveFile($file_srls, 'file'); $result = Spawn::delete(array('table' => Spawn::getTableName('article'), 'where' => 'nest_srl=' . (int) $post['nest_srl'], 'debug' => false)); } // remove category data if ($post['delete_category']) { $result = Spawn::delete(array('table' => Spawn::getTableName('category'), 'where' => 'nest_srl=' . (int) $post['nest_srl'], 'debug' => false)); } // remove nest data $result = Spawn::delete(array('table' => Spawn::getTableName($this->name), 'where' => 'srl=' . (int) $post['nest_srl'], 'debug' => false)); if ($result != 'success') { return array('state' => 'error', 'action' => 'back', 'message' => 'Fail execution database'); } // redirect url $params = $_SESSION['app_srl'] ? $_SESSION['app_srl'] . '/' : ''; $redirectUrl = __GOOSE_ROOT__ . 'nest/index/' . $params; return array('state' => 'success', 'action' => 'redirect', 'url' => $redirectUrl);
/** * api - action file_tmp to file * file_tmp에 있는 db데이터를 file로 옮긴다. * * @param array $file_tmp_srls * @param int|null $article_srl * @return array */ public function actDBFiletmpToFile($file_tmp_srls = array(), $article_srl = null) { if ($this->name != 'file') { return array('state' => 'error', 'message' => '잘못된 객체로 접근했습니다.'); } if (!$this->isAdmin) { return array('state' => 'error', 'message' => '권한이 없습니다.'); } foreach ($file_tmp_srls as $k => $v) { $data = $this->getItem(array('table' => Spawn::getTableName('file_tmp'), 'where' => 'srl=' . (int) $v)); $tmpData = $data['state'] == 'success' ? $data['data'] : null; $db_result = Spawn::insert(array('table' => Spawn::getTableName('file'), 'data' => array('srl' => null, 'article_srl' => $article_srl, 'name' => $tmpData['name'], 'loc' => $tmpData['loc'], 'type' => $tmpData['type'], 'size' => (int) $tmpData['size'], 'regdate' => $tmpData['regdate']))); if ($db_result != 'success') { return array('state' => 'error', 'message' => '[file] DB : Insert Error'); } $db_result2 = Spawn::delete(array('table' => Spawn::getTableName('file_tmp'), 'where' => 'srl=' . (int) $v)); if ($db_result2 != 'success') { return array('state' => 'error', 'message' => '[file_tmp] DB : remove Error'); } } return array('state' => 'success', 'message' => 'complete'); }