- Timestamp:
- 2011/11/24 15:15:19 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_11-dev/data/class/pages/mypage/LC_Page_Mypage_DownLoad.php
r21335 r21354 44 44 * Application/octet-streamで対応出来ないファイルタイプのみ拡張子をキーに記述する 45 45 * 拡張子が本配列に存在しない場合は $defaultContentTypeを利用する */ 46 var $arrContentType = array('apk' => 'application/vnd.android.package-archive'); 46 var $arrContentType = array('apk' => 'application/vnd.android.package-archive', 47 'pdf' => 'application/pdf' 48 ); 47 49 48 50 // }}} … … 132 134 // SC_DisplayやSC_Responseに大容量ファイルレスポンスが実装されたら移行可能だと思います。 133 135 136 // ダウンロード実行 モバイル端末はダウンロード方法が異なる 137 if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE){ 138 // キャリアがAUのモバイル端末はさらにダウンロード方法が異なる 139 if (SC_MobileUserAgent::getCarrier() == 'ezweb'){ 140 // AUモバイル 141 $this->lfMobileAuDownload($realpath,$sdown_filename); 142 }else{ 143 // AU以外のモバイル 144 $this->lfMobileDownload($realpath,$sdown_filename); 145 } 146 }else{ 147 // PC、スマフォ 148 $this->lfDownload($realpath,$sdown_filename); 149 } 150 } 151 152 /** 153 * 商品情報の読み込みを行う. 154 * 155 * @param integer $customer_id 会員ID 156 * @param integer $order_id 受注ID 157 * @param integer $product_id 商品ID 158 * @param integer $product_class_id 商品規格ID 159 * @return array 商品情報の配列 160 */ 161 function lfGetRealFileName($customer_id, $order_id, $product_id, $product_class_id) { 162 $objQuery = new SC_Query_Ex(); 163 $col = <<< __EOS__ 164 pc.product_id AS product_id, 165 pc.product_class_id AS product_class_id, 166 pc.down_realfilename AS down_realfilename, 167 pc.down_filename AS down_filename, 168 o.order_id AS order_id, 169 o.customer_id AS customer_id, 170 o.payment_date AS payment_date, 171 o.status AS status 172 __EOS__; 173 174 $table = <<< __EOS__ 175 dtb_products_class pc, 176 dtb_order_detail od, 177 dtb_order o 178 __EOS__; 179 180 $dbFactory = SC_DB_DBFactory_Ex::getInstance(); 181 $where = "o.customer_id = ? AND o.order_id = ? AND pc.product_id = ? AND pc.product_class_id = ?"; 182 $where .= " AND " . $dbFactory->getDownloadableDaysWhereSql('o'); 183 $where .= " = 1"; 184 $arrRet = $objQuery->select($col, $table, $where, 185 array($customer_id, $order_id, $product_id, $product_class_id)); 186 return $arrRet[0]; 187 } 188 189 /* パラメーター情報の初期化 */ 190 function lfInitParam(&$objFormParam) { 191 $objFormParam->addParam("customer_id", "customer_id", INT_LEN, 'n', array("EXIST_CHECK","NUM_CHECK")); 192 $objFormParam->addParam("order_id", "order_id", INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK")); 193 $objFormParam->addParam("product_id", "product_id", INT_LEN, 'n', array("EXIST_CHECK","NUM_CHECK")); 194 $objFormParam->addParam("product_class_id", "product_class_id", INT_LEN, 'n', array("EXIST_CHECK","NUM_CHECK")); 195 } 196 197 /* 入力内容のチェック */ 198 function lfCheckError(&$objFormParam) { 199 $objErr = new SC_CheckError_Ex($objFormParam->getHashArray()); 200 $objErr->arrErr = $objFormParam->checkError(); 201 return $objErr->arrErr; 202 } 203 204 /** 205 * モバイル端末用ヘッダー出力処理 206 * 207 * @param string $realpath ダウンロードファイルパス 208 * @param string $sdown_filename ダウンロード時の指定ファイル名 209 */ 210 function lfMobileHeader($realpath,$sdown_filename){ 211 $objHelperMobile = new SC_Helper_Mobile_Ex(); 212 //ファイルの拡張子からコンテンツタイプを取得する 213 $mime_type = $objHelperMobile->getMIMEType($realpath); 214 header('Content-Type: ' . $mime_type); 215 header("Content-Disposition: attachment; filename=" . $sdown_filename); 216 header('Accept-Ranges: bytes'); 217 header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT"); 218 header("Cache-Control: public"); 219 } 220 221 /** 222 * モバイル端末(AU)ダウンロード処理 223 * 224 * @param string $realpath ダウンロードファイルパス 225 * @param string $sdown_filename ダウンロード時の指定ファイル名 226 */ 227 function lfMobileAuDownload($realpath,$sdown_filename){ 228 //モバイル用ヘッダー出力 229 $this->lfMobileHeader($realpath,$sdown_filename); 230 //ファイルサイズを取得する 231 $file_size = filesize($realpath); 232 //読み込み 233 $fp = fopen( $realpath, "rb" ); 234 if (isset($_SERVER['HTTP_RANGE'])) { 235 // 二回目以降のリクエスト 236 list($range_offset, $range_limit) = sscanf($_SERVER['HTTP_RANGE'], "bytes=%d-%d"); 237 $content_range = sprintf("bytes %d-%d/%d", $range_offset, $range_limit, $file_size); 238 $content_length = $range_limit - $range_offset + 1; 239 fseek( $fp, $range_offset, SEEK_SET ); 240 header("HTTP/1.1 206 Partial Content" ); 241 header("Content-Lenth: " . $content_length); 242 header("Content-Range: " . $content_range); 243 } else { 244 // 一回目のリクエスト 245 $content_length = $file_size; 246 header("Content-Length: " . $content_length); 247 } 248 echo fread( $fp, $content_length ) ; 249 ob_flush(); 250 flush(); 251 } 252 253 /** 254 * モバイル端末(AU以外)ダウンロード処理 255 * 256 * @param string $realpath ダウンロードファイルパス 257 * @param string $sdown_filename ダウンロード時の指定ファイル名 258 */ 259 function lfMobileDownload($realpath,$sdown_filename){ 260 //モバイル用ヘッダー出力 261 $this->lfMobileHeader($realpath,$sdown_filename); 262 //ファイルサイズを取得する 263 $file_size = filesize($realpath); 264 265 //出力用バッファをクリアする 266 @ob_end_clean(); 267 268 //HTTP_RANGEがセットされていた場合 269 if (isset($_SERVER['HTTP_RANGE'])) { 270 // 二回目以降のリクエスト 271 list($a, $range) = explode("=",$_SERVER['HTTP_RANGE'],2); 272 list($range) = explode(",",$range,2); 273 list($range, $range_end) = explode("-", $range); 274 $range=intval($range); 275 276 if (!$range_end) { 277 $range_end=$file_size-1; 278 } else { 279 $range_end=intval($range_end); 280 } 281 282 $new_length = $range_end-$range+1; 283 header("HTTP/1.1 206 Partial Content"); 284 header("Content-Length: $new_length"); 285 header("Content-Range: bytes $range-$range_end/$file_size"); 286 } else { 287 // 一回目のリクエスト 288 $new_length=$file_size; 289 header("Content-Length: ".$file_size); 290 } 291 292 //ファイル読み込み 293 $chunksize = 1*(DOWNLOAD_BLOCK*1024); 294 $bytes_send = 0; 295 if ($realpath = fopen($realpath, 'r')) { 296 // 二回目以降のリクエスト 297 if (isset($_SERVER['HTTP_RANGE'])) fseek($realpath, $range); 298 299 while (!feof($realpath) && (!connection_aborted()) && ($bytes_send<$new_length)) { 300 $buffer = fread($realpath, $chunksize); 301 print($buffer); 302 ob_flush(); 303 flush(); 304 $bytes_send += strlen($buffer); 305 } 306 fclose($realpath); 307 } 308 die(); 309 } 310 311 /** 312 * モバイル端末以外ダウンロード処理 313 * 314 * @param string $realpath ダウンロードファイルパス 315 * @param string $sdown_filename ダウンロード時の指定ファイル名 316 */ 317 function lfDownload($realpath,$sdown_filename){ 134 318 // 拡張子を取得 135 319 $extension = pathinfo($realpath, PATHINFO_EXTENSION); … … 162 346 exit; 163 347 } 164 165 348 while (!feof($handle)) { 166 349 echo(fread($handle, DOWNLOAD_BLOCK*1024)); … … 172 355 173 356 /** 174 * 商品情報の読み込みを行う.175 *176 * @param integer $customer_id 会員ID177 * @param integer $order_id 受注ID178 * @param integer $product_id 商品ID179 * @param integer $product_class_id 商品規格ID180 * @return array 商品情報の配列181 */182 function lfGetRealFileName($customer_id, $order_id, $product_id, $product_class_id) {183 $objQuery = new SC_Query_Ex();184 $col = <<< __EOS__185 pc.product_id AS product_id,186 pc.product_class_id AS product_class_id,187 pc.down_realfilename AS down_realfilename,188 pc.down_filename AS down_filename,189 o.order_id AS order_id,190 o.customer_id AS customer_id,191 o.payment_date AS payment_date,192 o.status AS status193 __EOS__;194 195 $table = <<< __EOS__196 dtb_products_class pc,197 dtb_order_detail od,198 dtb_order o199 __EOS__;200 201 $dbFactory = SC_DB_DBFactory_Ex::getInstance();202 $where = "o.customer_id = ? AND o.order_id = ? AND pc.product_id = ? AND pc.product_class_id = ?";203 $where .= " AND " . $dbFactory->getDownloadableDaysWhereSql('o');204 $where .= " = 1";205 $arrRet = $objQuery->select($col, $table, $where,206 array($customer_id, $order_id, $product_id, $product_class_id));207 return $arrRet[0];208 }209 210 /* パラメーター情報の初期化 */211 function lfInitParam(&$objFormParam) {212 $objFormParam->addParam("customer_id", "customer_id", INT_LEN, 'n', array("EXIST_CHECK","NUM_CHECK"));213 $objFormParam->addParam("order_id", "order_id", INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK"));214 $objFormParam->addParam("product_id", "product_id", INT_LEN, 'n', array("EXIST_CHECK","NUM_CHECK"));215 $objFormParam->addParam("product_class_id", "product_class_id", INT_LEN, 'n', array("EXIST_CHECK","NUM_CHECK"));216 }217 218 /* 入力内容のチェック */219 function lfCheckError(&$objFormParam) {220 $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());221 $objErr->arrErr = $objFormParam->checkError();222 return $objErr->arrErr;223 }224 225 /**226 357 * デストラクタ. 227 358 *
Note: See TracChangeset
for help on using the changeset viewer.