コード例 #1
0
ファイル: action.php プロジェクト: baijd/magike
 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);
     }
 }
コード例 #2
0
ファイル: module.file_output.php プロジェクト: baijd/magike
 public function runModule()
 {
     if ($this->stack['static_var']['referer_denny'] && (!isset($_SERVER['HTTP_REFERER']) || 0 !== strpos($_SERVER['HTTP_REFERER'], $this->stack['static_var']['siteurl']))) {
         return '对不起,您要访问的资源不存在';
     }
     $fileModel = $this->loadModel('files');
     $file = $fileModel->fetchOneByKey($_GET['file_id']);
     if ($file && $file['file_name'] == $_GET['file_name']) {
         $path = __UPLOAD__ . mgGetGuidPath($file['file_guid']) . '/' . $file['file_guid'];
         if (file_exists($path)) {
             $this->stack['static_var']['content_type'] = $file['file_type'];
             return file_get_contents($path);
         } else {
             return '对不起,您要访问的资源不存在';
         }
     } else {
         return '对不起,您要访问的资源不存在';
     }
 }
コード例 #3
0
 public function runModule($args)
 {
     $require = array('width' => 80, 'height' => 80);
     $getArgs = $this->initArgs($args, $require);
     $fileModel = $this->loadModel('files');
     $file = $fileModel->fetchOneByKey($_GET['file_id']);
     if ($file && $file['file_name'] == $_GET['file_name']) {
         $path = __UPLOAD__ . mgGetGuidPath($file['file_guid']) . '/' . $file['file_guid'];
         if (file_exists($path) && function_exists("gd_info")) {
             $this->stack['static_var']['content_type'] = $file['file_type'] == 'image/pjpeg' ? 'image/jpeg' : $file['file_type'];
             $fileType = array();
             $supportItem = gd_info();
             if ($supportItem["GIF Read Support"] && $supportItem["GIF Create Support"]) {
                 $fileType[] = 'image/gif';
             }
             if ($supportItem["JPG Support"]) {
                 $fileType[] = 'image/jpeg';
                 $fileType[] = 'image/pjpeg';
             }
             if ($supportItem["PNG Support"]) {
                 $fileType[] = 'image/png';
             }
             if (in_array($file['file_type'], $fileType)) {
                 $size = getimagesize($path);
                 if ($size[0] > $getArgs['width']) {
                     $image = imagecreatefromstring(file_get_contents($path));
                     $dst = $this->getResampledImg($image, $size, array($getArgs['width'], $getArgs['height']), 0);
                     imagejpeg($dst, null, 100);
                 } else {
                     return file_get_contents($path);
                 }
                 return;
             } else {
                 return file_get_contents($path);
             }
         } else {
             return '对不起,您要访问的资源不存在';
         }
     } else {
         return '对不起,您要访问的资源不存在';
     }
 }
コード例 #4
0
ファイル: module.file_input.php プロジェクト: baijd/magike
 public function deleteFile()
 {
     $this->requireGet('file_id');
     $select = is_array($_GET['file_id']) ? $_GET['file_id'] : array($_GET['file_id']);
     $fileModel = $this->loadModel('files');
     foreach ($select as $val) {
         $file = $fileModel->fetchOneByKey($val);
         if ($file) {
             $fileModel->deleteByKeys($val);
             $path = __UPLOAD__ . mgGetGuidPath($file['file_guid']) . '/' . $file['file_guid'];
             if (file_exists($path)) {
                 unlink($path);
             }
             $this->result['open'] = true;
             $this->result['word'] = '您选中的文件已经被删除';
         } else {
             $this->result['open'] = true;
             $this->result['word'] = '您选中的文件不存在';
         }
     }
 }
コード例 #5
0
ファイル: module.xmlrpc_post.php プロジェクト: baijd/magike
 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']);
 }