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


PHP elFinder::rewind方法代码示例

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


在下文中一共展示了elFinder::rewind方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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, $dir, $name, $stat)
 {
     $this->clearcache();
     $mime = $stat['mime'];
     $w = !empty($stat['width']) ? $stat['width'] : 0;
     $h = !empty($stat['height']) ? $stat['height'] : 0;
     $id = $this->_joinPath($dir, $name);
     elFinder::rewind($fp);
     $stat = fstat($fp);
     $size = $stat['size'];
     if ($tmpfile = tempnam($this->tmpPath, $this->id)) {
         if (($trgfp = fopen($tmpfile, 'wb')) == false) {
             unlink($tmpfile);
         } else {
             while (!feof($fp)) {
                 fwrite($trgfp, fread($fp, 8192));
             }
             fclose($trgfp);
             chmod($tmpfile, 0644);
             $sql = $id > 0 ? 'REPLACE INTO %s (id, parent_id, name, content, size, mtime, mime, width, height) VALUES (' . $id . ', %d, \'%s\', LOAD_FILE(\'%s\'), %d, %d, \'%s\', %d, %d)' : 'INSERT INTO %s (parent_id, name, content, size, mtime, mime, width, height) VALUES (%d, \'%s\', LOAD_FILE(\'%s\'), %d, %d, \'%s\', %d, %d)';
             $sql = sprintf($sql, $this->tbf, $dir, $this->db->real_escape_string($name), $this->loadFilePath($tmpfile), $size, time(), $mime, $w, $h);
             $res = $this->query($sql);
             unlink($tmpfile);
             if ($res) {
                 return $id > 0 ? $id : $this->db->insert_id;
             }
         }
     }
     $content = '';
     elFinder::rewind($fp);
     while (!feof($fp)) {
         $content .= fread($fp, 8192);
     }
     $sql = $id > 0 ? 'REPLACE INTO %s (id, parent_id, name, content, size, mtime, mime, width, height) VALUES (' . $id . ', %d, \'%s\', \'%s\', %d, %d, \'%s\', %d, %d)' : 'INSERT INTO %s (parent_id, name, content, size, mtime, mime, width, height) VALUES (%d, \'%s\', \'%s\', %d, %d, \'%s\', %d, %d)';
     $sql = sprintf($sql, $this->tbf, $dir, $this->db->real_escape_string($name), $this->db->real_escape_string($content), $size, time(), $mime, $w, $h);
     unset($content);
     if ($this->query($sql)) {
         return $id > 0 ? $id : $this->db->insert_id;
     }
     return false;
 }
开发者ID:studio-42,项目名称:elfinder,代码行数:52,代码来源:elFinderVolumeMySQL.class.php

示例2: output

 /**
  * Output json
  *
  * @param  array  data to output
  * @return void
  * @author Dmitry (dio) Levashov
  **/
 protected function output(array $data)
 {
     // clear output buffer
     while (ob_get_level() && ob_end_clean()) {
     }
     $header = isset($data['header']) ? $data['header'] : $this->header;
     unset($data['header']);
     if ($header) {
         if (is_array($header)) {
             foreach ($header as $h) {
                 header($h);
             }
         } else {
             header($header);
         }
     }
     if (isset($data['pointer'])) {
         $toEnd = true;
         $fp = $data['pointer'];
         if (($this->reqMethod === 'GET' || $this->reqMethod === 'HEAD') && elFinder::isSeekableStream($fp) && array_search('Accept-Ranges: none', headers_list()) === false) {
             header('Accept-Ranges: bytes');
             $psize = null;
             if (!empty($_SERVER['HTTP_RANGE'])) {
                 $size = $data['info']['size'];
                 $start = 0;
                 $end = $size - 1;
                 if (preg_match('/bytes=(\\d*)-(\\d*)(,?)/i', $_SERVER['HTTP_RANGE'], $matches)) {
                     if (empty($matches[3])) {
                         if (empty($matches[1]) && $matches[1] !== '0') {
                             $start = $size - $matches[2];
                         } else {
                             $start = intval($matches[1]);
                             if (!empty($matches[2])) {
                                 $end = intval($matches[2]);
                                 if ($end >= $size) {
                                     $end = $size - 1;
                                 }
                                 $toEnd = $end == $size - 1;
                             }
                         }
                         $psize = $end - $start + 1;
                         header('HTTP/1.1 206 Partial Content');
                         header('Content-Length: ' . $psize);
                         header('Content-Range: bytes ' . $start . '-' . $end . '/' . $size);
                         fseek($fp, $start);
                     }
                 }
             }
             if (is_null($psize)) {
                 elFinder::rewind($fp);
             }
         } else {
             header('Accept-Ranges: none');
             if (isset($data['info']) && !$data['info']['size']) {
                 if (function_exists('header_remove')) {
                     header_remove('Content-Length');
                 } else {
                     header('Content-Length:');
                 }
             }
         }
         // unlock session data for multiple access
         $this->elFinder->getSession()->close();
         // client disconnect should abort
         ignore_user_abort(false);
         if ($reqMethod !== 'HEAD') {
             if ($toEnd) {
                 fpassthru($fp);
             } else {
                 $out = fopen('php://output', 'wb');
                 stream_copy_to_stream($fp, $out, $psize);
                 fclose($out);
             }
         }
         if (!empty($data['volume'])) {
             $data['volume']->close($data['pointer'], $data['info']['hash']);
         }
         exit;
     } else {
         if (!empty($data['raw']) && !empty($data['error'])) {
             echo $data['error'];
         } else {
             if (isset($data['debug']) && isset($data['debug']['phpErrors'])) {
                 $data['debug']['phpErrors'] = array_merge($data['debug']['phpErrors'], elFinder::$phpErrors);
             }
             echo json_encode($data);
         }
         flush();
         exit(0);
     }
 }
开发者ID:bigbrush,项目名称:yii2-big,代码行数:98,代码来源:elFinderConnector.class.php


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