Beispiel #1
0
 /**
  * 
  * 从gridfs直接输出到客户端
  */
 public function output()
 {
     /*
      * Mongo方式
     $grid=$this->getGridFS();
     		
     		$cursor = $grid->chunks->find(array('files_id' => $id))->sort(array('n' => 1));
     foreach($cursor as $chunk) {
         echo $chunk['data']->bin;
     }
     */
     //$bin = fastdfs_storage_download_file_to_buff($this->fs_group_name, $this->fs_filename);
     $bin = NDCS::download_file_to_buff($this->fs_group_name, $this->fs_filename);
     if (strlen($bin) > 0) {
         Core::header('Content-Type: ' . $this->mime);
         Core::header('Content-Length: ' . strlen($bin));
         echo $bin;
         Core::quit();
     } else {
         GridFS::fdfs_error($this->fs_group_name, $this->fs_filename);
     }
 }
Beispiel #2
0
 public function output($offset = 0, $length = 0)
 {
     //         $fdfs = new \FastDFS();
     //创建一个临时文件
     $tmp_file = Core::tempname();
     //从fastdfs下载到本地
     //             $fdfs->storage_download_file_to_file($this->fs_group_name, $this->fs_filename, $tmp_file);
     //$fdfs_result = fastdfs_storage_download_file_to_file($this->fs_group_name, $this->fs_filename, $tmp_file, $offset, $length);
     $fdfs_result = NDCS::download_file_to_file($this->fs_group_name, $this->fs_filename, $tmp_file, $offset, $length);
     if (!$fdfs_result) {
         GridFS::fdfs_error($this->fs_group_name, $this->fs_filename);
     }
     $fh = fopen($tmp_file, "rb");
     if ($fh) {
         //流输出
         while (!feof($fh)) {
             echo fread($fh, 4096);
             @ob_flush();
             @flush();
         }
         fclose($fh);
         //删除临时文件
         @unlink($tmp_file);
     } else {
         Core::fault(554);
     }
     //         $fdfs->tracker_close_all_connections();
     Core::quit();
 }
Beispiel #3
0
 /**
  * 同源文件格式转换
  * 已经转换过直接读取转换的文件;
  * 未转换实时转换并保存
  * @param array('mp3','m4r','mp4', 'gif') $type
  */
 public function output_convert($type)
 {
     //加入随机数到文件名避免线程冲突
     $orifile = Core::tempname(str_replace("'", "", rand(1, 100000) . '_' . $this->fid . '_' . $this->getFilename()));
     $convertfile = Core::tempname(str_replace("'", "", rand(1, 100000) . '_' . $this->fid . '_' . $this->getFilename()) . '.' . $type);
     if ($newfile = $this->getByFiletype($type)) {
         $newfile->output();
     } else {
         $fileSource = new FileSource();
         $fileSource->setFilename($this->mime, $this->size, $this->md5);
         if (!$fileSource->ifExist()) {
             Core::fault(404);
         }
         //$fdfs_result = fastdfs_storage_download_file_to_file($fileSource->fs_group_name, $fileSource->fs_filename, $orifile);
         $fdfs_result = NDCS::download_file_to_file($fileSource->fs_group_name, $fileSource->fs_filename, $orifile);
         if (!$fdfs_result) {
             GridFS::fdfs_error($fileSource->fs_group_name, $fileSource->fs_filename);
         }
         if ($type == 'mp3') {
             $cmd = Core::config('ffmpeg_binary') . ' -i \'' . $orifile . '\' -ar 20050 \'' . $convertfile . '\'';
         } elseif ($type == 'm4r') {
             $cmd = Core::config('ffmpeg_binary') . ' -i \'' . $orifile . '\' -ab 128000 -f mp4 -acodec libfaac \'' . $convertfile . '\'';
         } elseif ($type == 'mp4') {
             $cmd = Core::config('ffmpeg_binary') . ' -y -i \'' . $orifile . '\' -b 384k -vcodec libx264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8 -subq 6 -trellis 0 -refs 5 -bf 0 -flags2 +mixed_refs -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -acodec libfaac -ac 1 -ar 16000 -r 13 -ab 32000 \'' . $convertfile . '\'';
             //                 $logit = true;
         }
         if ($type == 'gif') {
             list($done, $code) = $this->_convert_gif($orifile, $convertfile);
         } else {
             $done = Core::cmdRun($cmd, $code);
         }
         //             if ($logit){
         //                 \MongoLogger::instance()->log('mp4_convert_debug',$done,array('fid'=>$this->fid,'code'=>$code,'md5'=>@md5_file($convertfile)));
         //             }
         if ($code) {
             Core::header('x-apiperf-cvtr:' . json_encode($done));
             Core::fault(500);
         }
         $filesize = filesize($convertfile);
         if ($filesize > 1) {
             if ($newfile = $this->putByFiletype($type, $convertfile)) {
                 //$newfile->output();
             } else {
                 Core::header('x-apiperf-puterr:1');
             }
         } else {
             Core::header('x-apiperf-cvtr:' . json_encode($convertfile));
             Core::fault(500);
         }
         Core::header("Content-Type: " . $newfile->mime . "; charset=UTF-8");
         Core::header('Cache-Control: public');
         //若去掉则ie无法弹出下载框
         //以附件下载显示的文件名
         Core::header_disposition($convertfile);
         Core::header_range($filesize, $start, $end, $length);
         Core::readfile($convertfile, $start, $length);
         Core::quit();
     }
 }