public function insertFile() { if (isset($_FILES['file']['name'])) { $guid = mgGetGuid(); $path = __UPLOAD__ . mgGetGuidPath($guid); if (!is_dir($path)) { mgMkdir($path); } move_uploaded_file($_FILES['file']['tmp_name'], $path . '/' . $guid); $fileModel = $this->loadModel('files'); $fileModel->insertTable(array('file_name' => $_FILES['file']['name'], 'file_type' => $_FILES['file']['type'], 'file_guid' => $guid, 'file_size' => $_FILES['file']['size'], 'file_time' => time() - $this->stack['static_var']['server_timezone'], 'file_describe' => $_POST['file_describe'])); } $this->result['open'] = true; $this->result['word'] = '您的文件 "' . $_FILES['file']['name'] . '" 已经提交成功'; }
public function buildCache() { $str = file_get_contents($this->compileFile); require __DIR__ . '/action/action_build.php'; require __DIR__ . '/action/template/template.template_build.php'; $objects = array_merge(mgRequireObjects(__DIR__ . '/action/template/build/core', '/build\\.([_a-zA-Z0-9-]+)\\.core\\.php/i'), mgRequireObjects(__DIR__ . '/action/template/build/filter', '/build\\.([_a-zA-Z0-9-]+)\\.filter\\.php/i')); foreach ($objects as $object) { $tmp = null; $tmp = new $object($str, $this->compileFile); $str = $tmp->prase(); } if (!is_dir(__COMPILE__)) { mgMkdir(__COMPILE__); } file_put_contents(__COMPILE__ . '/' . mgPathToFileName($this->compileFile) . '.php', $str); }
private function runAction() { //分析path模块传递的数据 $cacheTime = intval($this->stack['action']['cache']); $pastTime = false; if ($cacheTime) { $time = time(); $fileName = md5($_SERVER['REQUEST_URI']); $path = __HTML_CACHE__ . mgGetGuidPath($fileName); $filePath = $path . '/' . $fileName; $mimePath = $path . '/' . $fileName . '.mime'; if (!file_exists($filePath) || !file_exists($mimePath)) { $pastTime = true; } else { $pastTime = $cacheTime > $time - filemtime($filePath) ? false : true; } } else { //do nothing } if (!$cacheTime || $pastTime || __DEBUG__) { if (__DEBUG__ && !is_dir(__DIR__ . '/action/' . $this->stack['action']['action'])) { $this->throwException(E_ACTION_ACTIONNOTEXISTS, $this->stack['action']['action']); } else { $tmp = null; require_once __DIR__ . '/action/' . $this->stack['action']['action'] . '/action.' . $this->stack['action']['action'] . '.php'; eval('$tmp = new ' . mgFileNameToClassName($this->stack['action']['action']) . '("' . str_replace('{', '{$', $this->stack['action']["file"]) . '");'); $tmp->runAction(); } $contents = ob_get_contents(); if ($cacheTime) { if (!is_dir($path)) { mgMkdir($path); } file_put_contents($mimePath, $this->stack['action']['content_type']); file_put_contents($filePath, $contents); } ob_end_clean(); echo $contents; } else { header(file_get_contents($mimePath)); echo file_get_contents($filePath); } if (__DEBUG__) { global $debugData; mgPrintDebug(__DEBUG_LOG__, $debugData); } }
public function mwNewMediaObject($args) { $blogId = intval($args[0]); $userName = $args[1]; $password = $args[2]; $data = $args[3]; $guid = mgGetGuid(); $data['name'] = basename($data['name']); $path = __UPLOAD__ . mgGetGuidPath($guid); if (!is_dir($path)) { mgMkdir($path); } $success = file_put_contents($path . '/' . $guid, $data['bits']); $fileModel = $this->loadModel('files'); $insertId = $fileModel->insertTable(array('file_name' => $data['name'], 'file_type' => $data['type'], 'file_guid' => $guid, 'file_size' => strlen($data['bits']), 'file_describe' => $data['name'])); if (!$success) { return new IXR_Error(500, '写入' . $data['name'] . '文件时出错.'); } return array('file' => $data['name'], 'url' => $this->stack['static_var']['index'] . '/res/' . $insertId . '/' . $data['name'], 'type' => $data['type']); }