1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Core
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Core file uploader model
30: *
31: * @category Mage
32: * @package Mage_Core
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Core_Model_File_Uploader extends Varien_File_Uploader
36: {
37: /**
38: * Flag, that defines should DB processing be skipped
39: *
40: * @var bool
41: */
42: protected $_skipDbProcessing = false;
43:
44: /**
45: * Save file to storage
46: *
47: * @param array $result
48: * @return Mage_Core_Model_File_Uploader
49: */
50: protected function _afterSave($result)
51: {
52: if (empty($result['path']) || empty($result['file'])) {
53: return $this;
54: }
55:
56: /** @var $helper Mage_Core_Helper_File_Storage */
57: $helper = Mage::helper('core/file_storage');
58:
59: if ($helper->isInternalStorage() || $this->skipDbProcessing()) {
60: return $this;
61: }
62:
63: /** @var $dbHelper Mage_Core_Helper_File_Storage_Database */
64: $dbHelper = Mage::helper('core/file_storage_database');
65: $this->_result['file'] = $dbHelper->saveUploadedFile($result);
66:
67: return $this;
68: }
69:
70: /**
71: * Getter/Setter for _skipDbProcessing flag
72: *
73: * @param null|bool $flag
74: * @return bool|Mage_Core_Model_File_Uploader
75: */
76: public function skipDbProcessing($flag = null)
77: {
78: if (is_null($flag)) {
79: return $this->_skipDbProcessing;
80: }
81: $this->_skipDbProcessing = (bool)$flag;
82: return $this;
83: }
84:
85: /**
86: * Check protected/allowed extension
87: *
88: * @param string $extension
89: * @return boolean
90: */
91: public function checkAllowedExtension($extension)
92: {
93: //validate with protected file types
94: /** @var $validator Mage_Core_Model_File_Validator_NotProtectedExtension */
95: $validator = Mage::getSingleton('core/file_validator_notProtectedExtension');
96: if (!$validator->isValid($extension)) {
97: return false;
98: }
99:
100: return parent::checkAllowedExtension($extension);
101: }
102: }
103: