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


PHP elFinder::getIniBytes方法代码示例

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


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

示例1: _save

 /**
  * Create new file and write into it from file pointer.
  * Return new file path or false on error.
  *
  * @param resource $fp   file pointer
  * @param string   $dir  target dir path
  * @param string   $name file name
  * @param array    $stat file stat (required by some virtual fs)
  *
  * @return bool|string
  *
  * @author Dmitry (dio) Levashov
  **/
 protected function _save($fp, $path, $name, $stat)
 {
     if ($name !== '') {
         $path .= '/' . $name;
     }
     list($parentId, $itemId, $parent) = $this->_gd_splitPath($path);
     if ($name === '') {
         $stat['iid'] = $itemId;
     }
     if (!$stat || empty($stat['iid'])) {
         $opts = ['q' => sprintf('trashed=false and "%s" in parents and name="%s"', $parentId, $name), 'fields' => self::FETCHFIELDS_LIST];
         $srcFile = $this->_gd_query($opts);
         $srcFile = empty($srcFile) ? null : $srcFile[0];
     } else {
         $srcFile = $this->_gd_getFile($path);
     }
     try {
         $mode = 'update';
         $mime = isset($stat['mime']) ? $stat['mime'] : '';
         $file = new Google_Service_Drive_DriveFile();
         if ($srcFile) {
             $mime = $srcFile->getMimeType();
         } else {
             $mode = 'insert';
             $file->setName($name);
             $file->setParents([$parentId]);
         }
         if (!$mime) {
             $mime = self::mimetypeInternalDetect($name);
         }
         if ($mime === 'unknown') {
             $mime = 'application/octet-stream';
         }
         $file->setMimeType($mime);
         $size = 0;
         if (isset($stat['size'])) {
             $size = $stat['size'];
         } else {
             $fstat = fstat($fp);
             if (!empty($fstat['size'])) {
                 $size = $fstat['size'];
             }
         }
         // set chunk size (max: 100MB)
         $chunkSizeBytes = 100 * 1024 * 1024;
         if ($size > 0) {
             $memory = elFinder::getIniBytes('memory_limit');
             if ($memory) {
                 $chunkSizeBytes = min([$chunkSizeBytes, intval($memory / 4 / 256) * 256]);
             }
         }
         if ($size > $chunkSizeBytes) {
             $client = $this->client;
             // Call the API with the media upload, defer so it doesn't immediately return.
             $client->setDefer(true);
             if ($mode === 'insert') {
                 $request = $this->service->files->create($file, ['fields' => self::FETCHFIELDS_GET]);
             } else {
                 $request = $this->service->files->update($srcFile->getId(), $file, ['fields' => self::FETCHFIELDS_GET]);
             }
             // Create a media file upload to represent our upload process.
             $media = new Google_Http_MediaFileUpload($client, $request, $mime, null, true, $chunkSizeBytes);
             $media->setFileSize($size);
             // Upload the various chunks. $status will be false until the process is
             // complete.
             $status = false;
             while (!$status && !feof($fp)) {
                 elFinder::extendTimeLimit();
                 // read until you get $chunkSizeBytes from TESTFILE
                 // fread will never return more than 8192 bytes if the stream is read buffered and it does not represent a plain file
                 // An example of a read buffered file is when reading from a URL
                 $chunk = $this->_gd_readFileChunk($fp, $chunkSizeBytes);
                 $status = $media->nextChunk($chunk);
             }
             // The final value of $status will be the data from the API for the object
             // that has been uploaded.
             if ($status !== false) {
                 $obj = $status;
             }
             $client->setDefer(false);
         } else {
             $params = ['data' => stream_get_contents($fp), 'uploadType' => 'media', 'fields' => self::FETCHFIELDS_GET];
             if ($mode === 'insert') {
                 $obj = $this->service->files->create($file, $params);
             } else {
                 $obj = $this->service->files->update($srcFile->getId(), $file, $params);
             }
//.........这里部分代码省略.........
开发者ID:studio-42,项目名称:elfinder,代码行数:101,代码来源:elFinderVolumeGoogleDrive.class.php


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