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


PHP Helper::addTmpFileToMapper方法代码示例

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


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

示例1: testStreamFromLocalFile

 /**
  * @medium
  * test if stream wrapper can read files outside from the data folder
  */
 function testStreamFromLocalFile()
 {
     $filename = '/' . $this->userId . '/files/' . 'tmp-' . uniqid() . '.txt';
     $tmpFilename = "/tmp/" . uniqid() . ".txt";
     // write an encrypted file
     $cryptedFile = $this->view->file_put_contents($filename, $this->dataShort);
     // Test that data was successfully written
     $this->assertTrue(is_int($cryptedFile));
     // create a copy outside of the data folder in /tmp
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     $encryptedContent = $this->view->file_get_contents($filename);
     \OC_FileProxy::$enabled = $proxyStatus;
     file_put_contents($tmpFilename, $encryptedContent);
     \OCA\Encryption\Helper::addTmpFileToMapper($tmpFilename, $filename);
     // try to read the file from /tmp
     $handle = fopen("crypt://" . $tmpFilename, "r");
     $contentFromTmpFile = stream_get_contents($handle);
     // check if it was successful
     $this->assertEquals($this->dataShort, $contentFromTmpFile);
     // clean up
     unlink($tmpFilename);
     $this->view->unlink($filename);
 }
开发者ID:Romua1d,项目名称:core,代码行数:28,代码来源:stream.php

示例2: getFileSize

 /**
  * get the file size of the unencrypted file
  * @param string $path absolute path
  * @return bool
  */
 public function getFileSize($path)
 {
     $result = 0;
     // Disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     // split the path parts
     $pathParts = explode('/', $path);
     if (isset($pathParts[2]) && $pathParts[2] === 'files' && $this->view->file_exists($path) && $this->isEncryptedPath($path)) {
         $offset = 0;
         if ($this->containHeader($path)) {
             $offset = Crypt::BLOCKSIZE;
         }
         // get the size from filesystem if the file contains a encryption header we
         // we substract it
         $size = $this->view->filesize($path) - $offset;
         // fast path, else the calculation for $lastChunkNr is bogus
         if ($size === 0) {
             \OC_FileProxy::$enabled = $proxyStatus;
             return 0;
         }
         // calculate last chunk nr
         // next highest is end of chunks, one subtracted is last one
         // we have to read the last chunk, we can't just calculate it (because of padding etc)
         $lastChunkNr = ceil($size / Crypt::BLOCKSIZE) - 1;
         $lastChunkSize = $size - $lastChunkNr * Crypt::BLOCKSIZE;
         // open stream
         $stream = fopen('crypt://' . $path, "r");
         if (is_resource($stream)) {
             // calculate last chunk position
             $lastChunckPos = $lastChunkNr * Crypt::BLOCKSIZE;
             // seek to end
             if (@fseek($stream, $lastChunckPos) === -1) {
                 // storage doesn't support fseek, we need a local copy
                 fclose($stream);
                 $localFile = $this->view->getLocalFile($path);
                 Helper::addTmpFileToMapper($localFile, $path);
                 $stream = fopen('crypt://' . $localFile, "r");
                 if (fseek($stream, $lastChunckPos) === -1) {
                     // if fseek also fails on the local storage, than
                     // there is nothing we can do
                     fclose($stream);
                     \OCP\Util::writeLog('Encryption library', 'couldn\'t determine size of "' . $path, \OCP\Util::ERROR);
                     return $result;
                 }
             }
             // get the content of the last chunk
             $lastChunkContent = fread($stream, $lastChunkSize);
             // calc the real file size with the size of the last chunk
             $realSize = $lastChunkNr * 6126 + strlen($lastChunkContent);
             // store file size
             $result = $realSize;
         }
     }
     \OC_FileProxy::$enabled = $proxyStatus;
     return $result;
 }
开发者ID:droiter,项目名称:openwrt-on-android,代码行数:62,代码来源:util.php


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