00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Sales_DownloadController extends Mage_Core_Controller_Front_Action
00036 {
00037
00038
00039
00040
00041 public function downloadCustomOptionAction ()
00042 {
00043 $quoteItemOptionId = $this->getRequest()->getParam('id');
00044 $secretKey = $this->getRequest()->getParam('key');
00045 $option = Mage::getModel('sales/quote_item_option')->load($quoteItemOptionId);
00046
00047 if ($option->getId()) {
00048
00049 try {
00050 $info = unserialize($option->getValue());
00051
00052 if ($secretKey != $info['secret_key']) {
00053 throw new Exception();
00054 }
00055
00056 $filePath = Mage::getBaseDir() . $info['order_path'];
00057 if (!is_file($filePath) || !is_readable($filePath)) {
00058
00059 $filePath = Mage::getBaseDir() . $info['quote_path'];
00060 if (!is_file($filePath) || !is_readable($filePath)) {
00061 throw new Exception();
00062 }
00063 }
00064
00065 $this->getResponse()
00066 ->setHttpResponseCode(200)
00067 ->setHeader('Pragma', 'public', true)
00068 ->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
00069 ->setHeader('Content-type', $info['type'], true)
00070 ->setHeader('Content-Length', $info['size'])
00071 ->setHeader('Content-Disposition', 'inline' . '; filename='.$info['title']);
00072
00073 $this->getResponse()
00074 ->clearBody();
00075 $this->getResponse()
00076 ->sendHeaders();
00077
00078 readfile($filePath);
00079
00080 } catch (Exception $e) {
00081 $this->_forward('noRoute');
00082 }
00083
00084 } else {
00085 $this->_forward('noRoute');
00086 }
00087 }
00088 }