0

曲のダウンロードとなるはずのこのページがあります。ダウンロードはFirefoxで機能しますが、ChromeとSafariでは何も起こりません。これが私のコードです。

    public function download() {
    if (isset($this->request->get['order_download_id'])) {
        $order_download_id = $this->request->get['order_download_id'];
    } else {
        $order_download_id = 0;
    }
    $download_info = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_download od LEFT JOIN `" . DB_PREFIX . "order` o ON (od.order_id = o.order_id) WHERE o.customer_id = '" . (int)$this->customer->getId(). "' AND o.order_status_id > '0' AND o.order_status_id = '" . (int)$this->config->get('config_download_status') . "' AND od.order_download_id = '" . (int)$order_download_id . "'");

    if ($download_info->row) {
        $file = DIR_DOWNLOAD . $download_info->row['filename'];
        $mask = basename($download_info->row['mask']);
        $mime = 'application/octet-stream';
        $encoding = 'binary';

        if (!headers_sent()) {
            if (file_exists($file)) {
                header('Pragma: public');
                header('Expires: 0');
                header('Content-Description: File Transfer');
                header('Content-Type: ' . $mime);
                header('Content-Transfer-Encoding: ' . $encoding);
                header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
                header('Content-Length: ' . filesize($file));
                $file = readfile($file, 'rb');
                print($file);
            } else {
                exit('Error: Could not find file ' . $file . '!');
            }
        } else {
            exit('Error: Headers already sent out!');
        }
    }
}

私はこれを機能させるためにあらゆる種類の異なることを試みましたが、2つのブラウザでは何も起こりません...アイデアや助けがあれば幸いです...

4

2 に答える 2

3

readfile送信されたバイト数を返します。印刷する必要はありません。行を削除する必要がありますprint($file);。そうしないと、ヘッダーで指定されているよりも多くのバイトが送信Content-Lengthされ、一部のHTTPクライアントが応答を破棄することになります。

また、次のような奇妙なファイル名を検討してください

"\r\nLocation: http://evil.com\r\n\r\n<script>alert('XSS');</script>

あなたはそれを正しく扱っていますか?

于 2011-07-02T20:11:11.263 に答える
0

近くの構文を参照してください

header('Content-Disposition: attachment; filename="'.$file_name_with_space. '"');

またはそれはすることができます

header("Content-Disposition: attachment; filename='".$file_name_with_space."'" );

ここでゲームは引用符で囲まれていますが、正しく記述されている場合は文字列の一部として扱われ、そうでない場合はクラッシュします。

すべてのブラウザで動作します。IE、FF、Chrome、SAFARI個人的にチェックしました。

于 2012-02-02T09:47:10.977 に答える