Example #1
0
File: func.php Project: qeist/goose
/**
 * 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;
}
Example #2
0
if (!$this->isAdmin) {
    return array('state' => 'error', 'action' => 'back', 'message' => '권한이 없습니다.');
}
// check post
$errorValue = Util::checkExistValue($post, array('title', 'content'));
if ($errorValue) {
    return array('state' => 'error', 'action' => 'back', 'message' => "[{$errorValue}]값이 없습니다.");
}
// adjust value
if (!$isExternalTransaction) {
    $post['title'] = htmlspecialchars(addslashes($post['title']));
    $post['content'] = addslashes($post['content']);
}
// insert data
$result = Spawn::insert(array('table' => Spawn::getTableName($this->name), 'data' => array('srl' => null, 'app_srl' => (int) $post['app_srl'], 'nest_srl' => (int) $post['nest_srl'], 'category_srl' => (int) $post['category_srl'], 'title' => $post['title'], 'content' => $post['content'], 'hit' => 0, 'json' => $post['json'], 'ip' => $_SERVER['REMOTE_ADDR'], 'regdate' => date("YmdHis"), 'modate' => date("YmdHis")), 'debug' => false));
if ($result != 'success') {
    return array('state' => 'error', 'action' => 'back', 'message' => 'Fail execution database');
}
// get last insert srl
$last_srl = Spawn::getLastIdx();
// file upload
if (count($files['upload'])) {
    // load module
    $file = Module::load('file');
    // upload file
    $uploadFiles = $file->actUploadFiles($files['upload'], 'data/upload/original/', 'file', $last_srl);
}
// redirect url
$param = $post['nest_srl'] ? $post['nest_srl'] . '/' : '';
$param .= $post['nest_srl'] && $post['category_srl'] ? $post['category_srl'] . '/' : '';
return array('state' => 'success', 'action' => 'redirect', 'url' => __GOOSE_ROOT__ . 'article/index/' . $param);
Example #3
0
 /**
  * api - action upload files
  * 다수의 파일을 업로드한다. 데이터페이스에 있는 정보도 추가한다.
  *
  * @param array $file 파일목록($_FILES['name'])
  * @param string|null $dir 업로드 디렉토리
  * @param string $table 업로드 테이블 (file|file_tmp)
  * @param int $article_srl 마지막 article번호. 테이블이 file_tmp라면 필요없음
  * @return array
  */
 public function actUploadFiles($file = array(), $dir = null, $table = '', $article_srl = null)
 {
     if ($this->name != 'file') {
         return array('state' => 'error', 'message' => '잘못된 객체로 접근했습니다.');
     }
     if (!$this->isAdmin) {
         return array('state' => 'error', 'message' => '권한이 없습니다.');
     }
     // check table
     if ($table != 'file' && $table != 'file_tmp') {
         return array('state' => 'error', 'message' => '$table값이 잘못되었습니다.');
     }
     // check upload file
     if (!$file['name'] || is_array($file['name']) && !$file['name'][0]) {
         return array('state' => 'error', 'action' => 'back', 'message' => 'not found file');
     }
     // string to array
     if (!is_array($file['name'])) {
         $file['error'] = array($file['error']);
         $file['name'] = array($file['name']);
         $file['size'] = array($file['size']);
         $file['tmp_name'] = array($file['tmp_name']);
         $file['type'] = array($file['type']);
     }
     // set variable
     $result = array();
     $month = Date('Ym');
     // set path
     $path = $dir ? $dir : $this->set['upPath_original'] . '/';
     $path_absolute = __GOOSE_PWD__ . $path;
     // make directory
     if (!is_dir($path_absolute . $month)) {
         Util::createDirectory($path_absolute . $month, 0777);
     }
     // action upload
     for ($i = 0; $i < count($file['name']); $i++) {
         if ($file['error'][$i]) {
             $result[] = array('state' => 'error', 'message' => $file['error'][$i]);
             continue;
         }
         if ($file['size'][$i] > $this->set['limitFileSize']) {
             $result[] = array('state' => 'error', 'message' => 'The attachment size exceeds the allowable limit.');
             continue;
         }
         // check filename
         $file['name'][$i] = $this->checkFilename($file['name'][$i], false);
         if (!$file['name'][$i]) {
             $result[] = array('state' => 'error', 'message' => 'This file is a format that is not allowed.');
             continue;
         }
         // check exist file
         $file['name'][$i] = $this->checkExistFile($path_absolute . $month . '/', $file['name'][$i], null);
         // copy file
         if ($file['tmp_name'][$i] && is_dir($path_absolute . $month . '/')) {
             move_uploaded_file($file['tmp_name'][$i], $path_absolute . $month . '/' . $file['name'][$i]);
         } else {
             $result[] = array('state' => 'error', 'message' => 'upload error');
             continue;
         }
         // insert data
         if ($table == 'file') {
             $db_result = Spawn::insert(array('table' => Spawn::getTableName($table), 'data' => array('srl' => null, 'article_srl' => $article_srl, 'name' => $file['name'][$i], 'loc' => $path . $month . '/' . $file['name'][$i], 'type' => $file['type'][$i], 'size' => (int) $file['size'][$i], 'regdate' => date("YmdHis"))));
         } else {
             if ($table == 'file_tmp') {
                 $db_result = Spawn::insert(array('table' => Spawn::getTableName($table), 'data' => array('srl' => null, 'name' => $file['name'][$i], 'loc' => $path . $month . '/' . $file['name'][$i], 'type' => $file['type'][$i], 'size' => (int) $file['size'][$i], 'regdate' => date("YmdHis"))));
             } else {
                 $db_result = null;
             }
         }
         if ($db_result != 'success') {
             // remove file
             if (file_exists($path_absolute . $month . '/' . $file['name'][$i])) {
                 @unlink($path_absolute . $month . '/' . $file['name'][$i]);
             }
             $result[] = array('state' => 'error', 'message' => 'Fail execution database');
         } else {
             $result[] = array('state' => 'success', 'loc' => $path . $month . '/' . $file['name'][$i], 'name' => $file['name'][$i], 'size' => $file['size'][$i], 'type' => $file['type'][$i], 'srl' => (int) Spawn::getLastIdx());
         }
     }
     return $result;
 }