本文整理汇总了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.");
}
}
}