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


PHP getID3::fread_buffer_size方法代码示例

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


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

示例1: saveAttachment

 public function saveAttachment($name, $offset, $length, $image_mime = null)
 {
     try {
         // do not extract at all
         if ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_NONE) {
             $attachment = null;
             // do not set any
             // extract to return array
         } elseif ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_INLINE) {
             $this->fseek($offset);
             $attachment = $this->fread($length);
             // get whole data in one pass, till it is anyway stored in memory
             if ($attachment === false || strlen($attachment) != $length) {
                 throw new Exception('failed to read attachment data');
             }
             // assume directory path is given
         } else {
             // set up destination path
             $dir = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->getid3->option_save_attachments), DIRECTORY_SEPARATOR);
             if (!is_dir($dir) || !is_writable($dir)) {
                 // check supplied directory
                 throw new Exception('supplied path (' . $dir . ') does not exist, or is not writable');
             }
             $dest = $dir . DIRECTORY_SEPARATOR . $name . ($image_mime ? '.' . getid3_lib::ImageExtFromMime($image_mime) : '');
             // create dest file
             if (($fp_dest = fopen($dest, 'wb')) == false) {
                 throw new Exception('failed to create file ' . $dest);
             }
             // copy data
             $this->fseek($offset);
             $buffersize = $this->data_string_flag ? $length : $this->getid3->fread_buffer_size();
             $bytesleft = $length;
             while ($bytesleft > 0) {
                 if (($buffer = $this->fread(min($buffersize, $bytesleft))) === false || ($byteswritten = fwrite($fp_dest, $buffer)) === false || $byteswritten === 0) {
                     throw new Exception($buffer === false ? 'not enough data to read' : 'failed to write to destination file, may be not enough disk space');
                 }
                 $bytesleft -= $byteswritten;
             }
             fclose($fp_dest);
             $attachment = $dest;
         }
     } catch (Exception $e) {
         // close and remove dest file if created
         if (isset($fp_dest) && is_resource($fp_dest)) {
             fclose($fp_dest);
             unlink($dest);
         }
         // do not set any is case of error
         $attachment = null;
         $this->warning('Failed to extract attachment ' . $name . ': ' . $e->getMessage());
     }
     // seek to the end of attachment
     $this->fseek($offset + $length);
     return $attachment;
 }
开发者ID:fs-contributor,项目名称:rtMedia,代码行数:55,代码来源:getid3.php


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