當前位置: 首頁>>代碼示例>>PHP>>正文


PHP File::seek方法代碼示例

本文整理匯總了PHP中Bitrix\Main\IO\File::seek方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::seek方法的具體用法?PHP File::seek怎麽用?PHP File::seek使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Bitrix\Main\IO\File的用法示例。


在下文中一共展示了File::seek方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: ViewByUser


//.........這裏部分代碼省略.........
             //Handle ETag
             $ETag = md5($filename . $filesize . $filetime);
             if (array_key_exists("HTTP_IF_NONE_MATCH", $_SERVER) && $_SERVER['HTTP_IF_NONE_MATCH'] === $ETag) {
                 CHTTP::SetStatus("304 Not Modified");
                 header("Cache-Control: private, max-age=" . $cache_time . ", pre-check=" . $cache_time);
                 die;
             }
             header("ETag: " . $ETag);
             //Handle Last Modified
             if ($filetime > 0) {
                 $lastModified = gmdate('D, d M Y H:i:s', $filetime) . ' GMT';
                 if (array_key_exists("HTTP_IF_MODIFIED_SINCE", $_SERVER) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] === $lastModified) {
                     CHTTP::SetStatus("304 Not Modified");
                     header("Cache-Control: private, max-age=" . $cache_time . ", pre-check=" . $cache_time);
                     die;
                 }
             }
         }
         $utfName = CHTTP::urnEncode($attachment_name, "UTF-8");
         $translitName = CUtil::translit($attachment_name, LANGUAGE_ID, array("max_len" => 1024, "safe_chars" => ".", "replace_space" => '-'));
         if ($force_download) {
             //Disable zlib for old versions of php <= 5.3.0
             //it has broken Content-Length handling
             if (ini_get('zlib.output_compression')) {
                 ini_set('zlib.output_compression', 'Off');
             }
             if ($cur_pos > 0) {
                 CHTTP::SetStatus("206 Partial Content");
             } else {
                 CHTTP::SetStatus("200 OK");
             }
             header("Content-Type: " . $content_type);
             header("Content-Disposition: attachment; filename=\"" . $translitName . "\"; filename*=utf-8''" . $utfName);
             header("Content-Transfer-Encoding: binary");
             header("Content-Length: " . ($size - $cur_pos + 1));
             if (is_resource($src)) {
                 header("Accept-Ranges: bytes");
                 header("Content-Range: bytes " . $cur_pos . "-" . $size . "/" . $filesize);
             }
         } else {
             header("Content-Type: " . $content_type);
             header("Content-Disposition: inline; filename=\"" . $translitName . "\"; filename*=utf-8''" . $utfName);
         }
         if ($cache_time > 0) {
             header("Cache-Control: private, max-age=" . $cache_time . ", pre-check=" . $cache_time);
             if ($filetime > 0) {
                 header('Last-Modified: ' . $lastModified);
             }
         } else {
             header("Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0");
         }
         header("Expires: 0");
         header("Pragma: public");
         // Download from front-end
         if ($fastDownload) {
             if ($fromClouds) {
                 $filename = preg_replace('~^(http[s]?)(\\://)~i', '\\1.', $filename);
                 $cloudUploadPath = COption::GetOptionString('main', 'bx_cloud_upload', '/upload/bx_cloud_upload/');
                 header('X-Accel-Redirect: ' . $cloudUploadPath . $filename);
             } else {
                 $filename = $APPLICATION->ConvertCharset($filename, SITE_CHARSET, "UTF-8");
                 header('X-Accel-Redirect: ' . $filename);
             }
         } else {
             session_write_close();
             if ($specialchars) {
                 echo "<", "pre", ">";
                 if (is_resource($src)) {
                     while (!feof($src)) {
                         echo htmlspecialcharsbx(fread($src, 32768));
                     }
                     $file->close();
                 } else {
                     echo htmlspecialcharsbx($src->get($filename));
                 }
                 echo "<", "/pre", ">";
             } else {
                 if (is_resource($src)) {
                     $file->seek($cur_pos);
                     while (!feof($src) && $cur_pos <= $size) {
                         $bufsize = 131072;
                         //128K
                         if ($cur_pos + $bufsize > $size) {
                             $bufsize = $size - $cur_pos + 1;
                         }
                         $cur_pos += $bufsize;
                         echo fread($src, $bufsize);
                     }
                     $file->close();
                 } else {
                     $fp = fopen("php://output", "wb");
                     $src->setOutputStream($fp);
                     $src->get($filename);
                 }
             }
         }
     }
     CMain::FinalActions();
     die;
 }
開發者ID:nycmic,項目名稱:bittest,代碼行數:101,代碼來源:file.php


注:本文中的Bitrix\Main\IO\File::seek方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。