source: branches/version-2_11-dev/data/class/pages/mypage/LC_Page_Mypage_DownLoad.php @ 20937

Revision 20937, 8.1 KB checked in by eccuore, 13 years ago (diff)

fixes 1311 ダウンロード機能:コンテントファイルの連想配列化

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC CUORE
4 *
5 * Copyright(c) 2009 CUORE CO.,LTD. All Rights Reserved.
6 *
7 * http://ec.cuore.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23// {{{ requires
24require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
25
26/**
27 * ダウンロード商品ダウンロード のページクラス.
28 *
29 * @package Page
30 * @author CUORE CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Mypage_DownLoad extends LC_Page_Ex {
34
35    // {{{ properties
36
37    /** フォームパラメータの配列 */
38    var $objFormParam;
39
40    /** 基本Content-Type */
41    var $defaultContentType = 'Application/octet-stream';
42
43    /** 拡張Content-Type配列
44     * Application/octet-streamで対応出来ないファイルタイプのみ拡張子をキーに記述する
45     * 拡張子が本配列に存在しない場合は $defaultContentTypeを利用する */
46    var $arrContentType = array('apk' => 'application/vnd.android.package-archive');
47
48    // }}}
49    // {{{ functions
50
51    /**
52     * Page を初期化する.
53     *
54     * @return void
55     */
56    function init() {
57        parent::init();
58        $this->allowClientCache();
59    }
60
61    /**
62     * Page のプロセス.
63     *
64     * @return void
65     */
66    function process() {
67        ob_end_clean();
68        parent::process();
69        $this->action();
70        $this->sendResponse();
71    }
72
73    /**
74     * Page のAction.
75     *
76     * @return void
77     */
78    function action() {
79        // ログインチェック
80        $objCustomer = new SC_Customer_Ex();
81        if (!$objCustomer->isLoginSuccess()){
82            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
83        }
84
85        // パラメータチェック
86        $objFormParam = new SC_FormParam_Ex();
87        $this->lfInitParam($objFormParam);
88        // GET、SESSION['customer']値の取得
89        $objFormParam->setParam($_SESSION['customer']);
90        $objFormParam->setParam($_GET);
91        $this->arrErr = $this->lfCheckError($objFormParam);
92        if (count($this->arrErr)!=0){
93            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
94        }
95    }
96
97    /**
98     * Page のResponse.
99     *
100     * todo たいした処理でないのに異常に処理が重い
101     * @return void
102     */
103    function sendResponse() {
104        $this->objDisplay->noAction();
105
106        // パラメータ取得
107        $customer_id = $_SESSION['customer']['customer_id'];
108        $order_id = $_GET['order_id'];
109        $product_id = $_GET['product_id'];
110        $product_class_id = $_GET['product_class_id'];
111
112        //DBから商品情報の読込
113        $arrForm = $this->lfGetRealFileName($customer_id, $order_id, $product_id, $product_class_id);
114
115        //ファイル情報が無い場合はNG
116        if ($arrForm["down_realfilename"] == "" ){
117            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
118        }
119        //ファイルそのものが無い場合もとりあえずNG
120        $realpath = DOWN_SAVE_REALDIR . $arrForm["down_realfilename"];
121        if (!file_exists($realpath)){
122            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
123        }
124        //ファイル名をエンコードする Safariの対策はUTF-8で様子を見る
125        $encoding = "Shift_JIS";
126        if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'Safari')) {
127            $encoding = "UTF-8";
128        }
129        $sdown_filename = mb_convert_encoding($arrForm["down_filename"], $encoding, 'auto');
130
131        // flushなどを利用しているので、現行のSC_Displayは利用できません。
132        // SC_DisplayやSC_Responseに大容量ファイルレスポンスが実装されたら移行可能だと思います。
133
134        // 拡張子を取得
135        $extension = pathinfo($realpath, PATHINFO_EXTENSION);
136        $contentType = $this->defaultContentType;
137        // 拡張ContentType判定(拡張子をキーに拡張ContentType対象か判断)
138        if(isset($this->arrContentType[$extension])){
139            // 拡張ContentType対象の場合は、ContentTypeを変更
140            $contentType = $this->arrContentType[$extension];
141        }
142        header("Content-Type: ".$contentType);
143        //ファイル名指定
144        header('Content-Disposition: attachment; filename="' . $sdown_filename . '"');
145        header("Content-Transfer-Encoding: binary");
146        //キャッシュ無効化
147        header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
148        header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
149        //IE6+SSL環境下は、キャッシュ無しでダウンロードできない
150        header("Cache-Control: private");
151        header("Pragma: private");
152        //ファイルサイズ指定
153        $zv_filesize = filesize($realpath);
154        header("Content-Length: " . $zv_filesize);
155        set_time_limit(0);
156        ob_end_flush();
157        flush();
158        //ファイル読み込み
159        $handle = fopen($realpath, 'rb');
160        if ($handle === false) {
161            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
162            exit;
163        }
164
165        while (!feof($handle)) {
166            echo(fread($handle, DOWNLOAD_BLOCK*1024));
167            ob_flush();
168            flush();
169        }
170        fclose($handle);
171    }
172
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    /**
226     * デストラクタ.
227     *
228     * @return void
229     */
230    function destroy() {
231        parent::destroy();
232    }
233}
234?>
Note: See TracBrowser for help on using the repository browser.