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

Revision 20920, 7.3 KB checked in by nanasess, 13 years ago (diff)

#1301 (ダウンロード商品のダウンロードで, 無限ループの可能性)

  • fopen() の返り値をチェックするよう修正
  • data/class/SC_MobileImage.php でも同様の懸念があったため修正
  • 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
RevLine 
[18777]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
[20534]24require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
[18777]25
26/**
27 * ダウンロード商品ダウンロード のページクラス.
28 *
29 * @package Page
30 * @author CUORE CO.,LTD.
[20116]31 * @version $Id$
[18777]32 */
[20344]33class LC_Page_Mypage_DownLoad extends LC_Page_Ex {
[18777]34
[20562]35    // {{{ properties
[19957]36
37    /** フォームパラメータの配列 */
38    var $objFormParam;
39
[18777]40    // }}}
41    // {{{ functions
42
43    /**
44     * Page を初期化する.
45     *
46     * @return void
47     */
48    function init() {
49        parent::init();
50        $this->allowClientCache();
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process() {
[19911]59        ob_end_clean();
[19957]60        parent::process();
61        $this->action();
62        $this->sendResponse();
63    }
[19661]64
[19957]65    /**
66     * Page のAction.
67     *
68     * @return void
69     */
70    function action() {
71        // ログインチェック
[20490]72        $objCustomer = new SC_Customer_Ex();
[19957]73        if (!$objCustomer->isLoginSuccess()){
74            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
75        }
76
77        // パラメータチェック
[20501]78        $objFormParam = new SC_FormParam_Ex();
[20158]79        $this->lfInitParam($objFormParam);
[19957]80        // GET、SESSION['customer']値の取得
[20158]81        $objFormParam->setParam($_SESSION['customer']);
82        $objFormParam->setParam($_GET);
83        $this->arrErr = $this->lfCheckError($objFormParam);
[19957]84        if (count($this->arrErr)!=0){
85            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
86        }
87    }
88
89    /**
90     * Page のResponse.
[20158]91     *
92     * todo たいした処理でないのに異常に処理が重い
[19957]93     * @return void
94     */
95    function sendResponse() {
96        $this->objDisplay->noAction();
97
98        // パラメータ取得
[18793]99        $customer_id = $_SESSION['customer']['customer_id'];
100        $order_id = $_GET['order_id'];
101        $product_id = $_GET['product_id'];
[18824]102        $product_class_id = $_GET['product_class_id'];
[18793]103
[19661]104        //DBから商品情報の読込
105        $arrForm = $this->lfGetRealFileName($customer_id, $order_id, $product_id, $product_class_id);
[20891]106
[19661]107        //ファイル情報が無い場合はNG
108        if ($arrForm["down_realfilename"] == "" ){
109            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
110        }
111        //ファイルそのものが無い場合もとりあえずNG
[19805]112        $realpath = DOWN_SAVE_REALDIR . $arrForm["down_realfilename"];
[19661]113        if (!file_exists($realpath)){
114            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
115        }
116        //ファイル名をエンコードする Safariの対策はUTF-8で様子を見る
117        $encoding = "Shift_JIS";
118        if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'Safari')) {
119            $encoding = "UTF-8";
120        }
[20538]121        $sdown_filename = mb_convert_encoding($arrForm["down_filename"], $encoding, 'auto');
[19661]122
[19957]123        // flushなどを利用しているので、現行のSC_Displayは利用できません。
124        // SC_DisplayやSC_Responseに大容量ファイルレスポンスが実装されたら移行可能だと思います。
125
[19661]126        //タイプ指定
127        header("Content-Type: Application/octet-stream");
128        //ファイル名指定
129        header("Content-Disposition: attachment; filename=" . $sdown_filename);
130        header("Content-Transfer-Encoding: binary");
131        //キャッシュ無効化
132        header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
133        header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
134        //IE6+SSL環境下は、キャッシュ無しでダウンロードできない
135        header("Cache-Control: private");
136        header("Pragma: private");
137        //ファイルサイズ指定
138        $zv_filesize = filesize($realpath);
139        header("Content-Length: " . $zv_filesize);
140        set_time_limit(0);
141        ob_end_flush();
142        flush();
143        //ファイル読み込み
[20538]144        $handle = fopen($realpath, 'rb');
[20920]145        if ($handle === false) {
146            SC_Utils_Ex::sfDispSiteError(DOWNFILE_NOT_FOUND,"",true);
147            exit;
148        }
149
[19661]150        while (!feof($handle)) {
151            echo(fread($handle, DOWNLOAD_BLOCK*1024));
152            ob_flush();
[18777]153            flush();
154        }
[19661]155        fclose($handle);
[18777]156    }
157
[18793]158    /**
159     * 商品情報の読み込みを行う.
160     *
161     * @param integer $customer_id 顧客ID
162     * @param integer $order_id 受注ID
163     * @param integer $product_id 商品ID
[18824]164     * @param integer $product_class_id 商品規格ID
[18793]165     * @return array 商品情報の配列
166     */
[18824]167    function lfGetRealFileName($customer_id, $order_id, $product_id, $product_class_id) {
[20507]168        $objQuery = new SC_Query_Ex();
[18824]169        $col = <<< __EOS__
170            pc.product_id AS product_id,
171            pc.product_class_id AS product_class_id,
172            pc.down_realfilename AS down_realfilename,
173            pc.down_filename AS down_filename,
174            o.order_id AS order_id,
175            o.customer_id AS customer_id,
176            o.payment_date AS payment_date,
177            o.status AS status
178__EOS__;
179
180        $table = <<< __EOS__
181            dtb_products_class pc,
182            dtb_order_detail od,
183            dtb_order o
184__EOS__;
185
[18793]186        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
[18824]187        $where = "o.customer_id = ? AND o.order_id = ? AND pc.product_id = ? AND pc.product_class_id = ?";
[20358]188        $where .= " AND " . $dbFactory->getDownloadableDaysWhereSql('o');
[18793]189        $where .= " = 1";
190        $arrRet = $objQuery->select($col, $table, $where,
[18824]191                                    array($customer_id, $order_id, $product_id, $product_class_id));
[18777]192        return $arrRet[0];
193    }
194
[19957]195    /* パラメータ情報の初期化 */
[20158]196    function lfInitParam(&$objFormParam) {
[20538]197        $objFormParam->addParam("customer_id", "customer_id", INT_LEN, 'n', array("EXIST_CHECK","NUM_CHECK"));
198        $objFormParam->addParam("order_id", "order_id", INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK"));
199        $objFormParam->addParam("product_id", "product_id", INT_LEN, 'n', array("EXIST_CHECK","NUM_CHECK"));
200        $objFormParam->addParam("product_class_id", "product_class_id", INT_LEN, 'n', array("EXIST_CHECK","NUM_CHECK"));
[19957]201    }
202
203    /* 入力内容のチェック */
[20158]204    function lfCheckError(&$objFormParam) {
[20503]205        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
[20158]206        $objErr->arrErr = $objFormParam->checkError();
[19957]207        return $objErr->arrErr;
208    }
209
[18777]210    /**
211     * デストラクタ.
212     *
213     * @return void
214     */
215    function destroy() {
216        parent::destroy();
217    }
218}
219?>
Note: See TracBrowser for help on using the repository browser.