当前位置: 首页>>代码示例>>PHP>>正文


PHP MOXMAN_Util_PathUtils::getTempDir方法代码示例

本文整理汇总了PHP中MOXMAN_Util_PathUtils::getTempDir方法的典型用法代码示例。如果您正苦于以下问题:PHP MOXMAN_Util_PathUtils::getTempDir方法的具体用法?PHP MOXMAN_Util_PathUtils::getTempDir怎么用?PHP MOXMAN_Util_PathUtils::getTempDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MOXMAN_Util_PathUtils的用法示例。


在下文中一共展示了MOXMAN_Util_PathUtils::getTempDir方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processRequest

 /**
  * Sends the specified file with the correct mime type back to the browser.
  * This method gets called from the client side using the stream file.
  *
  * @param MOXMAN_Http_Context $httpContext Context instance to pass to use for the handler.
  */
 public function processRequest(MOXMAN_Http_Context $httpContext)
 {
     $request = $httpContext->getRequest();
     $response = $httpContext->getResponse();
     try {
         $file = MOXMAN::getFile($request->get("path"));
     } catch (Exception $e) {
         $response->setStatus("500", "Could not resolve path: " . $request->get("path"));
         if (MOXMAN::getLogger()) {
             MOXMAN::getLogger()->debug("Could not resolve path: " . $request->get("path"));
         }
         return;
     }
     // Create thumbnail
     if ($request->get("thumb")) {
         try {
             $file = $this->plugin->createThumbnail($file);
         } catch (Exception $e) {
             $response->setStatus("500", "Could not generate thumbnail.");
             $response->sendContent("Could not generate thumbnail.");
             return;
         }
     }
     // Fire before stream event
     $args = new MOXMAN_Vfs_StreamEventArgs($httpContext, $file);
     $this->plugin->fire("BeforeStream", $args);
     $file = $args->getFile();
     // Stream temp file if it exists
     if ($tempName = $request->get("tempname")) {
         $ext = MOXMAN_Util_PathUtils::getExtension($file->getName());
         $tempName = "mcic_" . md5(session_id() . $file->getName()) . "." . $ext;
         $tempFilePath = MOXMAN_Util_PathUtils::combine(MOXMAN_Util_PathUtils::getTempDir(), $tempName);
         if (file_exists($tempFilePath)) {
             $response->sendLocalFile($tempFilePath);
             return;
         }
     }
     $url = $file->getUrl();
     if ($url && !$request->get("stream", false)) {
         $response->redirect($url);
     } else {
         // Force 48h cache time
         $offset = 48 * 60 * 60;
         $response->setHeader("Cache-Control", "max-age=" . $offset);
         $response->setHeader("Date", gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
         $response->setHeader("Expires", gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
         $response->setHeader("Pragma", "public");
         $response->sendFile($file);
     }
 }
开发者ID:newton27,项目名称:dolphin.pro,代码行数:56,代码来源:StreamFileHandler.php

示例2: removeLocalTempFile

 /**
  * Removes the local temp file for a specific file instance.
  *
  * @param MOXMAN_Vfs_IFile File instance used to create a local temp file.
  */
 public function removeLocalTempFile(MOXMAN_Vfs_IFile $file)
 {
     if ($file->exists()) {
         $tempDir = MOXMAN_Util_PathUtils::combine(MOXMAN_Util_PathUtils::getTempDir($this->config), "moxman_blob_cache");
         $tempFile = MOXMAN_Util_PathUtils::combine($tempDir, md5($file->getPath() . $file->getLastModified()) . "." . MOXMAN_Util_PathUtils::getExtension($file->getName()));
         if (file_exists($tempFile)) {
             unlink($tempFile);
         }
     }
 }
开发者ID:newton27,项目名称:dolphin.pro,代码行数:15,代码来源:FileSystemManager.php

示例3: save

 /**
  * Executes the save command logic with the specified RPC parameters.
  *
  * @param Object $params Command parameters sent from client.
  * @return Object Result object to be passed back to client.
  */
 private function save($params)
 {
     $file = MOXMAN::getFile($params->path);
     $config = $file->getConfig();
     if ($config->get("general.demo")) {
         throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE);
     }
     if (!$file->canWrite()) {
         throw new MOXMAN_Exception("No write access to file: " . $file->getPublicPath(), MOXMAN_Exception::NO_WRITE_ACCESS);
     }
     $filter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "edit");
     if ($filter->accept($file) !== MOXMAN_Vfs_CombinedFileFilter::ACCEPTED) {
         throw new MOXMAN_Exception("Invalid file name for: " . $file->getPublicPath(), MOXMAN_Exception::INVALID_FILE_NAME);
     }
     // Import temp file as target file
     if (isset($params->tempname)) {
         $tempFilePath = MOXMAN_Util_PathUtils::combine(MOXMAN_Util_PathUtils::getTempDir(), $params->tempname);
         $file->importFrom($tempFilePath);
     }
     MOXMAN::getFileSystemManager()->removeLocalTempFile($file);
     $this->fireFileAction(MOXMAN_Core_FileActionEventArgs::ADD, $file);
     return parent::fileToJson($file, true);
 }
开发者ID:vidalweb,项目名称:MoxieManager,代码行数:29,代码来源:AlterImageCommand.php

示例4: processRequest

 /**
  * Process a request using the specified context.
  *
  * @param MOXMAN_Http_Context $httpContext Context instance to pass to use for the handler.
  */
 public function processRequest(MOXMAN_Http_Context $httpContext)
 {
     $tempFilePath = null;
     $chunkFilePath = null;
     $request = $httpContext->getRequest();
     $response = $httpContext->getResponse();
     try {
         // Check if the user is authenticated or not
         if (!MOXMAN::getAuthManager()->isAuthenticated()) {
             if (!isset($json->method) || !preg_match('/^(login|logout)$/', $json->method)) {
                 $exception = new MOXMAN_Exception("Access denied by authenticator(s).", 10);
                 $exception->setData(array("login_url" => MOXMAN::getConfig()->get("authenticator.login_page")));
                 throw $exception;
             }
         }
         $file = MOXMAN::getFile($request->get("path"));
         $config = $file->getConfig();
         if ($config->get('general.demo')) {
             throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE);
         }
         $maxSizeBytes = preg_replace("/[^0-9.]/", "", $config->get("upload.maxsize"));
         if (strpos(strtolower($config->get("upload.maxsize")), "k") > 0) {
             $maxSizeBytes = round(floatval($maxSizeBytes) * 1024);
         }
         if (strpos(strtolower($config->get("upload.maxsize")), "m") > 0) {
             $maxSizeBytes = round(floatval($maxSizeBytes) * 1024 * 1024);
         }
         function generateRandomString($length = 10)
         {
             $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
             $charactersLength = strlen($characters);
             $randomString = '';
             for ($i = 0; $i < $length; $i++) {
                 $randomString .= $characters[rand(0, $charactersLength - 1)];
             }
             return $randomString;
         }
         $filename = generateRandomString() . '.' . MOXMAN_Util_PathUtils::getExtension($request->get("name"));
         $id = $request->get("id");
         $loaded = intval($request->get("loaded", "0"));
         $total = intval($request->get("total", "-1"));
         $file = MOXMAN::getFile($file->getPath(), $filename);
         // Generate unique id for first chunk
         // TODO: We should cleanup orphan ID:s if upload fails etc
         if ($loaded == 0) {
             $id = uniqid();
         }
         // Setup path to temp file based on id
         $tempFilePath = MOXMAN_Util_PathUtils::combine(MOXMAN_Util_PathUtils::getTempDir(), "mcupload_" . $id . "." . MOXMAN_Util_PathUtils::getExtension($file->getName()));
         $chunkFilePath = MOXMAN_Util_PathUtils::combine(MOXMAN_Util_PathUtils::getTempDir(), "mcupload_chunk_" . $id . "." . MOXMAN_Util_PathUtils::getExtension($file->getName()));
         if (!$file->canWrite()) {
             throw new MOXMAN_Exception("No write access to path: " . $file->getPublicPath(), MOXMAN_Exception::NO_WRITE_ACCESS);
         }
         if ($total > $maxSizeBytes) {
             throw new MOXMAN_Exception("File size to large: " . $file->getPublicPath(), MOXMAN_Exception::FILE_SIZE_TO_LARGE);
         }
         // Operations on first chunk
         if ($loaded == 0) {
             // Fire before file action add event
             $args = new MOXMAN_Core_FileActionEventArgs("add", $file);
             $args->getData()->fileSize = $total;
             MOXMAN::getPluginManager()->get("core")->fire("BeforeFileAction", $args);
             $file = $args->getFile();
             if ($file->exists()) {
                 if (!$config->get("upload.overwrite") && !$request->get("overwrite")) {
                     throw new MOXMAN_Exception("Target file exists: " . $file->getPublicPath(), MOXMAN_Exception::FILE_EXISTS);
                 } else {
                     MOXMAN::getPluginManager()->get("core")->deleteThumbnail($file);
                     $file->delete();
                 }
             }
             $filter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "upload");
             if ($filter->accept($file) !== MOXMAN_Vfs_CombinedFileFilter::ACCEPTED) {
                 throw new MOXMAN_Exception("Invalid file name for: " . $file->getPublicPath(), MOXMAN_Exception::INVALID_FILE_NAME);
             }
         }
         $blobSize = 0;
         $inputFile = $request->getFile("file");
         if (!$inputFile) {
             throw new MOXMAN_Exception("No input file specified.");
         }
         if ($loaded === 0) {
             // Check if we should mock or not
             if (defined('PHPUNIT')) {
                 if (!copy($inputFile['tmp_name'], $tempFilePath)) {
                     throw new MOXMAN_Exception("Could not move the uploaded temp file.");
                 }
             } else {
                 if (!move_uploaded_file($inputFile['tmp_name'], $tempFilePath)) {
                     throw new MOXMAN_Exception("Could not move the uploaded temp file.");
                 }
             }
             $blobSize = filesize($tempFilePath);
         } else {
             // Check if we should mock or not
//.........这里部分代码省略.........
开发者ID:GHarutyunyan,项目名称:cms,代码行数:101,代码来源:UploadHandler.php


注:本文中的MOXMAN_Util_PathUtils::getTempDir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。