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


PHP Cart66Common::remoteFileSize方法代码示例

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


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

示例1: downloadFile

 public static function downloadFile($path)
 {
     // Validate the $path
     if (!strpos($path, '://')) {
         if ($productFolder = Cart66Setting::getValue('product_folder')) {
             if (strpos($path, $productFolder) === 0) {
                 // Erase and close all output buffers
                 while (@ob_end_clean()) {
                 }
                 // Get the name of the file to be downloaded
                 $fileName = basename($path);
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Download file name: {$fileName}");
                 // This is required for IE, otherwise Content-disposition is ignored
                 if (ini_get('zlib.output_compression')) {
                     ini_set('zlib.output_compression', 'Off');
                 }
                 $bytes = 'unknown';
                 if (substr($path, 0, 4) == 'http') {
                     $bytes = Cart66Common::remoteFileSize($path);
                 } else {
                     $bytes = filesize($path);
                 }
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Download file size: {$bytes}");
                 //open the file and stream download
                 if ($fp = fopen($path, 'rb')) {
                     ob_start();
                     header("Pragma: public");
                     header("Expires: 0");
                     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                     header("Cache-Control: private", false);
                     header("Content-Type: application/octet-stream;");
                     header('Content-Disposition: attachment; filename="' . $fileName . '"');
                     header("Content-Transfer-Encoding: binary");
                     header("Content-Length: {$bytes}");
                     while (!feof($fp)) {
                         //reset time limit for big files
                         @set_time_limit(0);
                         echo fread($fp, 1024 * 8);
                         flush();
                         ob_flush();
                     }
                     fclose($fp);
                 } else {
                     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] fopen failed to open path: {$path}");
                 }
             } else {
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Unable to download file because the requested file is not in the path defined by the product folder settings: {$path}");
             }
         } else {
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Unable to download file because the product folder is not set.");
         }
     }
 }
开发者ID:rbredow,项目名称:allyzabbacart,代码行数:53,代码来源:Cart66Common.php


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