Example #1
0
 public function testFileMethods()
 {
     $mock = dirname(__FILE__) . '/mock.txt';
     $mock2 = dirname(__FILE__) . '/mock2.txt';
     touch($mock);
     // copy file
     $this->assertTrue(is_readable($mock));
     FileHandler::copyFile($mock, $mock2);
     $this->assertTrue(is_readable($mock2));
     // remove file
     $this->assertTrue(FileHandler::removeFile($mock2));
     $this->assertFalse(is_readable($mock2));
     $this->assertFalse(FileHandler::removeFile($mock2));
     // rename file
     $this->assertTrue(FileHandler::rename($mock, $mock2));
     $this->assertFalse(is_readable($mock));
     $this->assertTrue(is_readable($mock2));
     $this->assertFalse(FileHandler::rename($mock, $mock2));
     // move file
     $this->assertTrue(FileHandler::rename($mock2, $mock));
     $this->assertTrue(is_readable($mock));
     $this->assertFalse(is_readable($mock2));
     $this->assertTrue(touch($mock2) && is_readable($mock2));
     $this->assertTrue(FileHandler::moveFile($mock, $mock2));
     $this->assertFalse(is_readable($mock));
     $this->assertTrue(is_readable($mock2));
     // remove file
     $this->assertFalse(FileHandler::removeFile($mock));
     $this->assertTrue(FileHandler::removeFile($mock2));
     $this->assertFalse(is_readable($mock));
     $this->assertFalse(is_readable($mock2));
 }
 /**
  * Regenerate all cache files
  * @return void
  */
 function procAdminRecompileCacheFile()
 {
     // rename cache dir
     $temp_cache_dir = './files/cache_' . $_SERVER['REQUEST_TIME'];
     FileHandler::rename('./files/cache', $temp_cache_dir);
     FileHandler::makeDir('./files/cache');
     // remove module extend cache
     FileHandler::removeFile(_XE_PATH_ . 'files/config/module_extend.php');
     // remove debug files
     FileHandler::removeFile(_XE_PATH_ . 'files/_debug_message.php');
     FileHandler::removeFile(_XE_PATH_ . 'files/_debug_db_query.php');
     FileHandler::removeFile(_XE_PATH_ . 'files/_db_slow_query.php');
     $oModuleModel = getModel('module');
     $module_list = $oModuleModel->getModuleList();
     // call recompileCache for each module
     foreach ($module_list as $module) {
         $oModule = NULL;
         $oModule = getClass($module->module);
         if (method_exists($oModule, 'recompileCache')) {
             $oModule->recompileCache();
         }
     }
     // remove cache
     $truncated = array();
     $oObjectCacheHandler = CacheHandler::getInstance('object');
     $oTemplateCacheHandler = CacheHandler::getInstance('template');
     if ($oObjectCacheHandler->isSupport()) {
         $truncated[] = $oObjectCacheHandler->truncate();
     }
     if ($oTemplateCacheHandler->isSupport()) {
         $truncated[] = $oTemplateCacheHandler->truncate();
     }
     if (count($truncated) && in_array(FALSE, $truncated)) {
         return new Object(-1, 'msg_self_restart_cache_engine');
     }
     // remove cache dir
     $tmp_cache_list = FileHandler::readDir('./files', '/(^cache_[0-9]+)/');
     if ($tmp_cache_list) {
         foreach ($tmp_cache_list as $tmp_dir) {
             if ($tmp_dir) {
                 FileHandler::removeDir('./files/' . $tmp_dir);
             }
         }
     }
     // remove duplicate indexes (only for CUBRID)
     $db_type = Context::getDBType();
     if ($db_type == 'cubrid') {
         $db = DB::getInstance();
         $db->deleteDuplicateIndexes();
     }
     // check autoinstall packages
     $oAutoinstallAdminController = getAdminController('autoinstall');
     $oAutoinstallAdminController->checkInstalled();
     $this->setMessage('success_updated');
 }
Example #3
0
 /**
  * Regenerate all cache files
  * @return void
  */
 function procAdminRecompileCacheFile()
 {
     // rename cache dir
     $temp_cache_dir = './files/cache_' . time();
     FileHandler::rename('./files/cache', $temp_cache_dir);
     FileHandler::makeDir('./files/cache');
     // remove debug files
     FileHandler::removeFile(_XE_PATH_ . 'files/_debug_message.php');
     FileHandler::removeFile(_XE_PATH_ . 'files/_debug_db_query.php');
     FileHandler::removeFile(_XE_PATH_ . 'files/_db_slow_query.php');
     $oModuleModel =& getModel('module');
     $module_list = $oModuleModel->getModuleList();
     // call recompileCache for each module
     foreach ($module_list as $module) {
         $oModule = null;
         $oModule =& getClass($module->module);
         if (method_exists($oModule, 'recompileCache')) {
             $oModule->recompileCache();
         }
     }
     // remove cache
     $truncated = array();
     $oObjectCacheHandler =& CacheHandler::getInstance('object');
     $oTemplateCacheHandler =& CacheHandler::getInstance('template');
     if ($oObjectCacheHandler->isSupport()) {
         $truncated[] = $oObjectCacheHandler->truncate();
     }
     if ($oTemplateCacheHandler->isSupport()) {
         $truncated[] = $oTemplateCacheHandler->truncate();
     }
     if (count($truncated) && in_array(false, $truncated)) {
         return new Object(-1, 'msg_self_restart_cache_engine');
     }
     // remove cache dir
     $tmp_cache_list = FileHandler::readDir('./files', '/(^cache_[0-9]+)/');
     if ($tmp_cache_list) {
         foreach ($tmp_cache_list as $tmp_dir) {
             if ($tmp_dir) {
                 FileHandler::removeDir('./files/' . $tmp_dir);
             }
         }
     }
     // remove duplicate indexes (only for CUBRID)
     $db_type =& Context::getDBType();
     if ($db_type == 'cubrid') {
         $db =& DB::getInstance();
         $db->deleteDuplicateIndexes();
     }
     $this->setMessage('success_updated');
 }
Example #4
0
 /**
  * Convert a directory of old language files to the Rhymix format.
  * 
  * @param string $dir
  * @param array $xml_langs When converting XML to PHP, only convert these languages. (Optional)
  * @return void
  */
 public static function convertDirectory($dir, $xml_langs = array())
 {
     if (file_exists("{$dir}/lang.xml")) {
         $langs = count($xml_langs) ? $xml_langs : array_keys(Lang::getSupportedList());
         foreach ($langs as $lang) {
             self::compileXMLtoPHP("{$dir}/lang.xml", $lang === 'ja' ? 'jp' : $lang, "{$dir}/{$lang}.php");
         }
     } else {
         $files = glob($dir . '/*.lang.php');
         foreach ($files as $filename) {
             $new_filename = preg_replace('/\\.lang\\.php$/', '.php', str_replace('jp.lang', 'ja.lang', $filename));
             \FileHandler::rename($filename, $new_filename);
         }
     }
 }
Example #5
0
 /**
  * Execute update
  *
  * @return Object
  */
 function moduleUpdate()
 {
     $oDB =& DB::getInstance();
     $oModuleController = getController('module');
     // Check member directory
     FileHandler::makeDir('./files/member_extra_info/image_name');
     FileHandler::makeDir('./files/member_extra_info/image_mark');
     FileHandler::makeDir('./files/member_extra_info/signature');
     FileHandler::makeDir('./files/member_extra_info/profile_image');
     // Add a column
     if (!$oDB->isColumnExists("member_auth_mail", "is_register")) {
         $oDB->addColumn("member_auth_mail", "is_register", "char", 1, "N", true);
     }
     // Add a column(site_srl) to "member_group_member" table (11/15/2008)
     if (!$oDB->isColumnExists("member_group_member", "site_srl")) {
         $oDB->addColumn("member_group_member", "site_srl", "number", 11, 0, true);
         $oDB->addIndex("member_group_member", "idx_site_srl", "site_srl", false);
     }
     if (!$oDB->isColumnExists("member_group", "site_srl")) {
         $oDB->addColumn("member_group", "site_srl", "number", 11, 0, true);
         $oDB->addIndex("member_group", "idx_site_title", array("site_srl", "title"), true);
     }
     if ($oDB->isIndexExists("member_group", "uni_member_group_title")) {
         $oDB->dropIndex("member_group", "uni_member_group_title", true);
     }
     // Add a column(list_order) to "member_group" table (05/18/2011)
     if (!$oDB->isColumnExists("member_group", "list_order")) {
         $oDB->addColumn("member_group", "list_order", "number", 11, '', true);
         $oDB->addIndex("member_group", "idx_list_order", "list_order", false);
         $output = executeQuery('member.updateAllMemberGroupListOrder');
     }
     // Add a column for image_mark (02/14/2009)
     if (!$oDB->isColumnExists("member_group", "image_mark")) {
         $oDB->addColumn("member_group", "image_mark", "text");
     }
     // Add a column for password expiration date
     if (!$oDB->isColumnExists("member", "change_password_date")) {
         $oDB->addColumn("member", "change_password_date", "date");
         executeQuery('member.updateAllChangePasswordDate');
     }
     // Add columns of question and answer to verify a password
     if (!$oDB->isColumnExists("member", "find_account_question")) {
         $oDB->addColumn("member", "find_account_question", "number", 11);
     }
     if (!$oDB->isColumnExists("member", "find_account_answer")) {
         $oDB->addColumn("member", "find_account_answer", "varchar", 250);
     }
     if (!$oDB->isColumnExists("member", "list_order")) {
         $oDB->addColumn("member", "list_order", "number", 11);
         @set_time_limit(0);
         $args->list_order = 'member_srl';
         executeQuery('member.updateMemberListOrderAll', $args);
         executeQuery('member.updateMemberListOrderAll');
     }
     if (!$oDB->isIndexExists("member", "idx_list_order")) {
         $oDB->addIndex("member", "idx_list_order", array("list_order"));
     }
     $oModuleModel = getModel('module');
     $config = $oModuleModel->getModuleConfig('member');
     $oModuleController = getController('module');
     // check agreement value exist
     if ($config->agreement) {
         $agreement_file = _XE_PATH_ . 'files/member_extra_info/agreement_' . Context::get('lang_type') . '.txt';
         $output = FileHandler::writeFile($agreement_file, $config->agreement);
         $config->agreement = NULL;
         $output = $oModuleController->updateModuleConfig('member', $config);
     }
     $oMemberAdminController = getAdminController('member');
     // check signup form ordering info
     if (!$config->signupForm || !is_array($config->signupForm)) {
         $identifier = 'user_id';
         $config->signupForm = $oMemberAdminController->createSignupForm($identifier);
         $config->identifier = $identifier;
         unset($config->agreement);
         $output = $oModuleController->updateModuleConfig('member', $config);
     }
     if ($config->skin) {
         $config_parse = explode('.', $config->skin);
         if (count($config_parse) > 1) {
             $template_path = sprintf('./themes/%s/modules/member/', $config_parse[0]);
             if (is_dir($template_path)) {
                 $config->skin = implode('|@|', $config_parse);
                 $oModuleController = getController('module');
                 $oModuleController->updateModuleConfig('member', $config);
             }
         }
     }
     if (is_readable('./files/member_extra_info/agreement.txt')) {
         $source_file = _XE_PATH_ . 'files/member_extra_info/agreement.txt';
         $target_file = _XE_PATH_ . 'files/member_extra_info/agreement_' . Context::get('lang_type') . '.txt';
         FileHandler::rename($source_file, $target_file);
     }
     FileHandler::makeDir('./files/ruleset');
     if (!is_readable('./files/ruleset/insertMember.xml')) {
         $oMemberAdminController->_createSignupRuleset($config->signupForm);
     }
     if (!is_readable('./files/ruleset/login.xml')) {
         $oMemberAdminController->_createLoginRuleset($config->identifier);
     }
     if (!is_readable('./files/ruleset/find_member_account_by_question.xml')) {
         $oMemberAdminController->_createFindAccountByQuestion($config->identifier);
     }
     // 2013. 11. 22 add menu when popup document menu called
     if (!$oModuleModel->getTrigger('document.getDocumentMenu', 'member', 'controller', 'triggerGetDocumentMenu', 'after')) {
         $oModuleController->insertTrigger('document.getDocumentMenu', 'member', 'controller', 'triggerGetDocumentMenu', 'after');
     }
     if (!$oModuleModel->getTrigger('comment.getCommentMenu', 'member', 'controller', 'triggerGetCommentMenu', 'after')) {
         $oModuleController->insertTrigger('comment.getCommentMenu', 'member', 'controller', 'triggerGetCommentMenu', 'after');
     }
     return new Object(0, 'success_updated');
 }
 /**
  * @brief Apply member points saved by file to units of 5,000 people
  */
 function procPointAdminApplyPoint()
 {
     $position = (int) Context::get('position');
     $total = (int) Context::get('total');
     if (!file_exists('./files/cache/pointRecal.txt')) {
         return new Object(-1, 'msg_invalid_request');
     }
     $idx = 0;
     $f = fopen("./files/cache/pointRecal.txt", "r");
     while (!feof($f)) {
         $str = trim(fgets($f, 1024));
         $idx++;
         if ($idx > $position) {
             list($member_srl, $point) = explode(',', $str);
             $args = new stdClass();
             $args->member_srl = $member_srl;
             $args->point = $point;
             $output = executeQuery('point.insertPoint', $args);
             if ($idx % 5000 == 0) {
                 break;
             }
         }
     }
     if (feof($f)) {
         FileHandler::removeFile('./files/cache/pointRecal.txt');
         $idx = $total;
         FileHandler::rename('./files/member_extra_info/point', './files/member_extra_info/point.old');
         FileHandler::removeDir('./files/member_extra_info/point.old');
     }
     fclose($f);
     $this->add('total', $total);
     $this->add('position', $idx);
     $this->setMessage(sprintf(Context::getLang('point_recal_message'), $idx, $total));
 }
 /**
  * @brief 첨부파일 정리
  **/
 function importAttaches($fp, $module_srl, $upload_target_srl, &$files)
 {
     $uploaded_count = 0;
     $started = false;
     $buff = null;
     while (!feof($fp)) {
         $str = trim(fgets($fp, 1024));
         // </attaches>로 끝나면 중단
         if (trim($str) == '</attaches>') {
             break;
         }
         // <attach>로 시작하면 첨부파일 수집
         if (trim($str) == '<attach>') {
             $file_obj = null;
             $file_obj->file_srl = getNextSequence();
             $file_obj->upload_target_srl = $upload_target_srl;
             $file_obj->module_srl = $module_srl;
             $started = true;
             $buff = null;
             // <file>로 시작하면 xml파일내의 첨부파일로 처리
         } else {
             if (trim($str) == '<file>') {
                 $file_obj->file = $this->saveTemporaryFile($fp);
                 continue;
             }
         }
         if ($started) {
             $buff .= $str;
         }
         // </attach>로 끝나면 첨부파일 정리
         if (trim($str) == '</attach>') {
             $xmlDoc = $this->oXmlParser->parse($buff . $str);
             $file_obj->source_filename = base64_decode($xmlDoc->attach->filename->body);
             $file_obj->download_count = base64_decode($xmlDoc->attach->download_count->body);
             if (!$file_obj->file) {
                 $url = base64_decode($xmlDoc->attach->url->body);
                 $path = base64_decode($xmlDoc->attach->path->body);
                 if ($path && file_exists($path)) {
                     $file_obj->file = $path;
                 } else {
                     $file_obj->file = $this->getTmpFilename();
                     FileHandler::getRemoteFile($url, $file_obj->file);
                 }
             }
             if (file_exists($file_obj->file)) {
                 // 이미지인지 기타 파일인지 체크하여 upload path 지정
                 if (preg_match("/\\.(jpg|jpeg|gif|png|wmv|wma|mpg|mpeg|avi|swf|flv|mp1|mp2|mp3|asaf|wav|asx|mid|midi|asf|mov|moov|qt|rm|ram|ra|rmm|m4v)\$/i", $file_obj->source_filename)) {
                     $path = sprintf("./files/attach/images/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3));
                     $filename = $path . $file_obj->source_filename;
                     $file_obj->direct_download = 'Y';
                 } else {
                     $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3));
                     $filename = $path . md5(crypt(rand(1000000, 900000), rand(0, 100)));
                     $file_obj->direct_download = 'N';
                 }
                 // 디렉토리 생성
                 if (!FileHandler::makeDir($path)) {
                     continue;
                 }
                 if (preg_match('/^\\.\\/files\\/cache\\/importer/i', $file_obj->file)) {
                     FileHandler::rename($file_obj->file, $filename);
                 } else {
                     @copy($file_obj->file, $filename);
                 }
                 // DB입력
                 unset($file_obj->file);
                 if (file_exists($filename)) {
                     $file_obj->uploaded_filename = $filename;
                     $file_obj->file_size = filesize($filename);
                     $file_obj->comment = NULL;
                     $file_obj->member_srl = 0;
                     $file_obj->sid = md5(rand(rand(1111111, 4444444), rand(4444445, 9999999)));
                     $file_obj->isvalid = 'Y';
                     $output = executeQuery('file.insertFile', $file_obj);
                     if ($output->toBool()) {
                         $uploaded_count++;
                         $tmp_obj = null;
                         $tmp_obj->source_filename = $file_obj->source_filename;
                         if ($file_obj->direct_download == 'Y') {
                             $files[$file_obj->source_filename] = $file_obj->uploaded_filename;
                         } else {
                             $files[$file_obj->source_filename] = getUrl('', 'module', 'file', 'act', 'procFileDownload', 'file_srl', $file_obj->file_srl, 'sid', $file_obj->sid);
                         }
                     }
                 }
             }
         }
     }
     return $uploaded_count;
 }
 /**
  * Import attachment
  * @param resource $fp
  * @param int $module_srl
  * @param int $upload_target_srl
  * @param array $files
  * @return int
  */
 function importAttaches($fp, $module_srl, $upload_target_srl, &$files)
 {
     $uploaded_count = 0;
     $started = false;
     $buff = null;
     $file_obj = new stdClass();
     while (!feof($fp)) {
         $str = trim(fgets($fp, 1024));
         // If it ends with </attaches>, break
         if (trim($str) == '</attaches>') {
             break;
         }
         // If it starts with <attach>, collect attachments
         if (trim($str) == '<attach>') {
             $file_obj->file_srl = getNextSequence();
             $file_obj->upload_target_srl = $upload_target_srl;
             $file_obj->module_srl = $module_srl;
             $started = true;
             $buff = null;
             // If it starts with <file>, handle the attachement in xml file
         } else {
             if (trim($str) == '<file>') {
                 $file_obj->file = $this->saveTemporaryFile($fp);
                 continue;
             }
         }
         if ($started) {
             $buff .= $str;
         }
         // If it ends with </attach>, handle attachements
         if (trim($str) == '</attach>') {
             $xmlDoc = $this->oXmlParser->parse($buff . $str);
             $file_obj->source_filename = base64_decode($xmlDoc->attach->filename->body);
             $file_obj->download_count = base64_decode($xmlDoc->attach->download_count->body);
             if (!$file_obj->file) {
                 $url = base64_decode($xmlDoc->attach->url->body);
                 $path = base64_decode($xmlDoc->attach->path->body);
                 if ($path && file_exists($path)) {
                     $file_obj->file = $path;
                 } else {
                     $file_obj->file = $this->getTmpFilename();
                     FileHandler::getRemoteFile($url, $file_obj->file);
                 }
             }
             if (file_exists($file_obj->file)) {
                 // Set upload path by checking if the attachement is an image or other kind of file
                 if (preg_match("/\\.(jpe?g|gif|png|wm[va]|mpe?g|avi|swf|flv|mp[1-4]|as[fx]|wav|midi?|moo?v|qt|r[am]{1,2}|m4v)\$/i", $file_obj->source_filename)) {
                     // Immediately remove the direct file if it has any kind of extensions for hacking
                     $file_obj->source_filename = preg_replace('/\\.(php|phtm|phar|html?|cgi|pl|exe|jsp|asp|inc)/i', '$0-x', $file_obj->source_filename);
                     $file_obj->source_filename = str_replace(array('<', '>'), array('%3C', '%3E'), $file_obj->source_filename);
                     $path = sprintf("./files/attach/images/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3));
                     $ext = substr(strrchr($file_obj->source_filename, '.'), 1);
                     $_filename = md5(crypt(rand(1000000, 900000), rand(0, 100))) . '.' . $ext;
                     $filename = $path . $_filename;
                     $idx = 1;
                     while (file_exists($filename)) {
                         $filename = $path . preg_replace('/\\.([a-z0-9]+)$/i', '_' . $idx . '.$1', $_filename);
                         $idx++;
                     }
                     $file_obj->direct_download = 'Y';
                 } else {
                     $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3));
                     $filename = $path . md5(crypt(rand(1000000, 900000), rand(0, 100)));
                     $file_obj->direct_download = 'N';
                 }
                 // Create a directory
                 if (!FileHandler::makeDir($path)) {
                     continue;
                 }
                 if (strncmp('./files/cache/importer/', $file_obj->file, 23) === 0) {
                     FileHandler::rename($file_obj->file, $filename);
                 } else {
                     copy($file_obj->file, $filename);
                 }
                 // Insert the file to the DB
                 unset($file_obj->file);
                 if (file_exists($filename)) {
                     $file_obj->uploaded_filename = $filename;
                     $file_obj->file_size = filesize($filename);
                     $file_obj->comment = NULL;
                     $file_obj->member_srl = 0;
                     $file_obj->sid = md5(rand(rand(1111111, 4444444), rand(4444445, 9999999)));
                     $file_obj->isvalid = 'Y';
                     $output = executeQuery('file.insertFile', $file_obj);
                     if ($output->toBool()) {
                         $uploaded_count++;
                         $tmp_obj = null;
                         $tmp_obj->source_filename = $file_obj->source_filename;
                         if ($file_obj->direct_download == 'Y') {
                             $files[$file_obj->source_filename] = $file_obj->uploaded_filename;
                         } else {
                             $files[$file_obj->source_filename] = getUrl('', 'module', 'file', 'act', 'procFileDownload', 'file_srl', $file_obj->file_srl, 'sid', $file_obj->sid);
                         }
                     }
                 }
             }
         }
     }
     return $uploaded_count;
 }
 /**
  * @brief 특정 디렉토리를 이동
  **/
 function moveDir($source_dir, $target_dir)
 {
     FileHandler::rename($source_dir, $target_dir);
 }
Example #10
0
 /**
  * Attachment
  * @param resource $fp
  * @param int $module_srl
  * @param int $upload_target_srl
  * @param array $files
  * @param string $buff
  * @return bool
  */
 function importAttaches($fp, $module_srl, $upload_target_srl, &$files, $buff)
 {
     $uploaded_count = 0;
     $file_obj = null;
     $file_obj->file_srl = getNextSequence();
     $file_obj->upload_target_srl = $upload_target_srl;
     $file_obj->module_srl = $module_srl;
     while (!feof($fp)) {
         $str = fgets($fp, 1024);
         // If it ends with </attaches>, break
         if (trim($str) == '</attachment>') {
             break;
         }
         // If it starts with <file>, handle the attachement in the xml file
         if (substr($str, 0, 9) == '<content>') {
             $file_obj->file = $this->saveTemporaryFile($fp, $str);
             continue;
         }
         $buff .= $str;
     }
     if (!file_exists($file_obj->file)) {
         return false;
     }
     $buff .= '</attachment>';
     $xmlDoc = $this->oXmlParser->parse($buff);
     $file_obj->source_filename = $xmlDoc->attachment->label->body;
     $file_obj->download_count = $xmlDoc->attachment->downloads->body;
     $name = $xmlDoc->attachment->name->body;
     // Set upload path by checking if the attachement is an image or other kind of file
     if (preg_match("/\\.(jpg|jpeg|gif|png|wmv|wma|mpg|mpeg|avi|swf|flv|mp1|mp2|mp3|mp4|asf|wav|asx|mid|midi|asf|mov|moov|qt|rm|ram|ra|rmm|m4v)\$/i", $file_obj->source_filename)) {
         $path = sprintf("./files/attach/images/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3));
         $filename = $path . $file_obj->source_filename;
         $file_obj->direct_download = 'Y';
     } else {
         $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3));
         $filename = $path . md5(crypt(rand(1000000, 900000), rand(0, 100)));
         $file_obj->direct_download = 'N';
     }
     // Create a directory
     if (!FileHandler::makeDir($path)) {
         return;
     }
     FileHandler::rename($file_obj->file, $filename);
     // Insert to the DB
     unset($file_obj->file);
     $file_obj->uploaded_filename = $filename;
     $file_obj->file_size = filesize($filename);
     $file_obj->comment = NULL;
     $file_obj->member_srl = 0;
     $file_obj->sid = md5(rand(rand(1111111, 4444444), rand(4444445, 9999999)));
     $file_obj->isvalid = 'Y';
     $output = executeQuery('file.insertFile', $file_obj);
     if ($output->toBool()) {
         $uploaded_count++;
         $tmp_obj = null;
         if ($file_obj->direct_download == 'Y') {
             $files[$name]->url = $file_obj->uploaded_filename;
         } else {
             $files[$name]->url = getUrl('', 'module', 'file', 'act', 'procFileDownload', 'file_srl', $file_obj->file_srl, 'sid', $file_obj->sid);
         }
         $files[$name]->direct_download = $file_obj->direct_download;
         $files[$name]->source_filename = $file_obj->source_filename;
         return true;
     }
     return false;
 }
Example #11
0
 /**
  * Move an attachement to the other document
  *
  * @param int $source_srl Sequence of target to move
  * @param int $target_module_srl New squence of module
  * @param int $target_srl New sequence of target
  * @return void
  **/
 function moveFile($source_srl, $target_module_srl, $target_srl)
 {
     if ($source_srl == $target_srl) {
         return;
     }
     $oFileModel =& getModel('file');
     $file_list = $oFileModel->getFiles($source_srl);
     if (!$file_list) {
         return;
     }
     $file_count = count($file_list);
     for ($i = 0; $i < $file_count; $i++) {
         unset($file_info);
         $file_info = $file_list[$i];
         $old_file = $file_info->uploaded_filename;
         // Determine the file path by checking if the file is an image or other kinds
         if (preg_match("/\\.(jpg|jpeg|gif|png|wmv|wma|mpg|mpeg|avi|swf|flv|mp1|mp2|mp3|mp4|asf|wav|asx|mid|midi|asf|mov|moov|qt|rm|ram|ra|rmm|m4v)\$/i", $file_info->source_filename)) {
             $path = sprintf("./files/attach/images/%s/%s/", $target_module_srl, $target_srl);
             $new_file = $path . $file_info->source_filename;
         } else {
             $path = sprintf("./files/attach/binaries/%s/%s/", $target_module_srl, $target_srl);
             $new_file = $path . md5(crypt(rand(1000000, 900000), rand(0, 100)));
         }
         // Pass if a target document to move is same
         if ($old_file == $new_file) {
             continue;
         }
         // Create a directory
         FileHandler::makeDir($path);
         // Move the file
         FileHandler::rename($old_file, $new_file);
         // Update DB information
         unset($args);
         $args->file_srl = $file_info->file_srl;
         $args->uploaded_filename = $new_file;
         $args->module_srl = $file_info->module_srl;
         $args->upload_target_srl = $target_srl;
         executeQuery('file.updateFile', $args);
     }
 }
Example #12
0
 /**
  * @brief 특정 글의 첨부파일을 다른 글로 이동
  **/
 function moveFile($source_srl, $target_module_srl, $target_srl)
 {
     if ($source_srl == $target_srl) {
         return;
     }
     $oFileModel =& getModel('file');
     $file_list = $oFileModel->getFiles($source_srl);
     if (!$file_list) {
         return;
     }
     $file_count = count($file_list);
     for ($i = 0; $i < $file_count; $i++) {
         unset($file_info);
         $file_info = $file_list[$i];
         $old_file = $file_info->uploaded_filename;
         // 이미지인지 기타 파일인지 체크하여 이동할 위치 정함
         if (preg_match("/\\.(jpg|jpeg|gif|png|wmv|wma|mpg|mpeg|avi|swf|flv|mp1|mp2|mp3|asaf|wav|asx|mid|midi|asf|mov|moov|qt|rm|ram|ra|rmm|m4v)\$/i", $file_info->source_filename)) {
             $path = sprintf("./files/attach/images/%s/%s/", $target_module_srl, $target_srl);
             $new_file = $path . $file_info->source_filename;
         } else {
             $path = sprintf("./files/attach/binaries/%s/%s/", $target_module_srl, $target_srl);
             $new_file = $path . md5(crypt(rand(1000000, 900000), rand(0, 100)));
         }
         // 이전 대상이 동일하면 그냥 패스
         if ($old_file == $new_file) {
             continue;
         }
         // 디렉토리 생성
         FileHandler::makeDir($path);
         // 파일 이동
         FileHandler::rename($old_file, $new_file);
         // DB 정보도 수정
         unset($args);
         $args->file_srl = $file_info->file_srl;
         $args->uploaded_filename = $new_file;
         $args->module_srl = $file_info->module_srl;
         $args->upload_target_srl = $target_srl;
         executeQuery('file.updateFile', $args);
     }
 }