當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。