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


PHP ZendT_Lib::getTmpDir方法代码示例

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


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

示例1: _clearFiles

 private function _clearFiles()
 {
     $folder = ZendT_Lib::getTmpDir() . '/files/';
     $dh = opendir($folder);
     while ($handle = readdir($dh)) {
         if (is_dir($folder . $handle) && $handle != '.' && $handle != '..') {
             $files = glob($folder . $handle . "/*.*");
             if (count($files) == 0) {
                 $path = $folder . $handle;
                 @rmdir($path);
             } else {
                 foreach ($files as $file) {
                     $lastAccess = filemtime($file);
                     // 30 minutos
                     if (time() - $lastAccess > 30 * 60 * 1) {
                         @unlink($file);
                     }
                 }
             }
         }
     }
     closedir($dh);
 }
开发者ID:rtsantos,项目名称:mais,代码行数:23,代码来源:File.php

示例2: pluploadAction

 public function pluploadAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $json = new ZendT_Json_Result();
     try {
         $targetDir = ZendT_Lib::getTmpDir() . '/files/' . DIRECTORY_SEPARATOR . "plupload";
         // Create target dir
         if (!file_exists($targetDir)) {
             @($result = mkdir($targetDir));
             if (!$result) {
                 throw new ZendT_Exception_Error('Não foi possível criar o diretório "$targetDir".', 1001);
             }
         }
         if (!file_exists($targetDir)) {
             @($result = mkdir($targetDir));
             if (!$result) {
                 throw new ZendT_Exception_Error('Não foi possível criar o diretório "$targetDir".', 1001);
             }
         }
         //$targetDir = 'uploads';
         $cleanupTargetDir = true;
         // Remove old files
         $maxFileAge = 1 * 3600;
         // Temp file age in seconds
         // 5 minutes execution time
         @set_time_limit(5 * 60);
         // Uncomment this one to fake upload time
         // usleep(5000);
         // Get parameters
         $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
         $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
         $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
         // Clean the fileName for security reasons
         $fileName = removeAccent(trim($fileName));
         $fileName = preg_replace('/[^\\w\\._]+/', '_', $fileName);
         $fileName = str_replace(' ', '_', $fileName);
         // Make sure the fileName is unique but only if chunking is disabled
         if ($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) {
             $ext = strrpos($fileName, '.');
             $fileName_a = substr($fileName, 0, $ext);
             $fileName_b = substr($fileName, $ext);
             $count = 1;
             while (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b)) {
                 $count++;
             }
             $fileName = $fileName_a . '_' . $count . $fileName_b;
         }
         $filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;
         // Remove old temp files
         if ($cleanupTargetDir && is_dir($targetDir) && ($dir = opendir($targetDir))) {
             while (($file = readdir($dir)) !== false) {
                 $tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file;
                 // Remove temp file if it is older than the max age and is not the current file
                 if (preg_match('/\\.part$/', $file) && filemtime($tmpfilePath) < time() - $maxFileAge && $tmpfilePath != "{$filePath}.part") {
                     @unlink($tmpfilePath);
                 }
             }
             closedir($dir);
         } else {
             throw new ZendT_Exception_Error('Failed to open temp directory.', 100);
         }
         // Look for the content type header
         if (isset($_SERVER["HTTP_CONTENT_TYPE"])) {
             $contentType = $_SERVER["HTTP_CONTENT_TYPE"];
         }
         if (isset($_SERVER["CONTENT_TYPE"])) {
             $contentType = $_SERVER["CONTENT_TYPE"];
         }
         // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
         if (strpos($contentType, "multipart") !== false) {
             if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
                 // Open temp file
                 $out = fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
                 if ($out) {
                     // Read binary input stream and append it to temp file
                     $in = fopen($_FILES['file']['tmp_name'], "rb");
                     if ($in) {
                         while ($buff = fread($in, 4096)) {
                             fwrite($out, $buff);
                         }
                     } else {
                         throw new ZendT_Exception_Error('Failed to open input stream.', 101);
                     }
                     fclose($in);
                     fclose($out);
                     @unlink($_FILES['file']['tmp_name']);
                 } else {
                     throw new ZendT_Exception_Error('Failed to open output stream.', 102);
                 }
             } else {
                 throw new ZendT_Exception_Error('Failed to move uploaded file.', 103);
             }
         } else {
             // Open temp file
             $out = fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
             if ($out) {
                 // Read binary input stream and append it to temp file
                 $in = fopen("php://input", "rb");
                 if ($in) {
//.........这里部分代码省略.........
开发者ID:rtsantos,项目名称:mais,代码行数:101,代码来源:FileController.php

示例3: create

 /**
  * Cria o arquivo no servidor e retorna o caminho completo do mesmo
  *
  * @param string $name
  * @param string $content
  * @return \ZendT_File
  * @throws ZendT_Exception_Error 
  */
 public function create($name = '', $content = '', $type = '', $id = '')
 {
     $this->_name = str_replace(':', '', $name);
     if ($this->_name == '') {
         $this->_name = md5(date('dmyhis') . rand(200000, 9999999999)) . '.tmp';
     }
     $this->_type = $type;
     $this->setId($id);
     //  $filename = $this->getPathBase() . '/' . $this->getFolderBase() . '/' . $this->_name;
     $this->getFolderBase();
     $filename = ZendT_Lib::getTmpDir() . '/files' . '/' . $this->getFolderBase() . '/' . $this->_name;
     if (file_exists($filename)) {
         @unlink($filename);
     }
     @($result = fopen($filename, 'a+'));
     if (!$result) {
         $error = error_get_last();
         throw new ZendT_Exception_Error('Erro ao criar o arquivo.' . substr($error['message'], 0, 1000));
     }
     if ($content) {
         @($write = fwrite($result, $content));
         if (!$write) {
             $error = error_get_last();
             throw new ZendT_Exception_Error('Erro ao escrever no arquivo.' . substr($error['message'], 0, 1000));
         }
     }
     return $this;
 }
开发者ID:rtsantos,项目名称:mais,代码行数:36,代码来源:File.php


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