- Timestamp:
- 2012/01/17 16:21:07 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_11-dev/data/class/pages/mypage/LC_Page_Mypage_DownLoad.php
r21354 r21405 44 44 * Application/octet-streamで対応出来ないファイルタイプのみ拡張子をキーに記述する 45 45 * 拡張子が本配列に存在しない場合は $defaultContentTypeを利用する */ 46 var $arrContentType = array('apk' => 'application/vnd.android.package-archive', 47 'pdf' => 'application/pdf' 48 ); 46 var $arrContentType = array('apk' => 'application/vnd.android.package-archive'); 49 47 50 48 // }}} … … 134 132 // SC_DisplayやSC_Responseに大容量ファイルレスポンスが実装されたら移行可能だと思います。 135 133 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 会員ID156 * @param integer $order_id 受注ID157 * @param integer $product_id 商品ID158 * @param integer $product_class_id 商品規格ID159 * @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 status172 __EOS__;173 174 $table = <<< __EOS__175 dtb_products_class pc,176 dtb_order_detail od,177 dtb_order o178 __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){318 134 // 拡張子を取得 319 135 $extension = pathinfo($realpath, PATHINFO_EXTENSION); … … 346 162 exit; 347 163 } 164 348 165 while (!feof($handle)) { 349 166 echo(fread($handle, DOWNLOAD_BLOCK*1024)); … … 355 172 356 173 /** 174 * 商品情報の読み込みを行う. 175 * 176 * @param integer $customer_id 会員ID 177 * @param integer $order_id 受注ID 178 * @param integer $product_id 商品ID 179 * @param integer $product_class_id 商品規格ID 180 * @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 status 193 __EOS__; 194 195 $table = <<< __EOS__ 196 dtb_products_class pc, 197 dtb_order_detail od, 198 dtb_order o 199 __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 /** 357 226 * デストラクタ. 358 227 *
Note: See TracChangeset
for help on using the changeset viewer.