admin/includes/classes/upload.php | 61 +++++++++++++++++++++++++++++----------
1 file changed, 45 insertions(+), 16 deletions(-)
diff --git a/admin/includes/classes/upload.php b/admin/includes/classes/upload.php
index 9584e4e..1fb6112 100644
|
a
|
b
|
defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'
|
| 26 | 26 | $this->set_destination($destination); |
| 27 | 27 | $this->set_permissions($permissions); |
| 28 | 28 | $this->set_extensions($extensions); |
| | 29 | $this->set_mime_types($mime_types); |
| 29 | 30 | |
| 30 | 31 | if (xtc_not_null($this->file) && xtc_not_null($this->destination)) { |
| 31 | 32 | if ( ($this->parse() == true) && ($this->save() == true) ) { |
| … |
… |
defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'
|
| 37 | 38 | } |
| 38 | 39 | |
| 39 | 40 | function parse() { |
| 40 | | global $messageStack; |
| 41 | | |
| | 41 | |
| 42 | 42 | $file = array(); |
| 43 | 43 | |
| 44 | 44 | if (isset($_FILES[$this->file])) { |
| … |
… |
defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'
|
| 68 | 68 | if (isset($file['tmp_name']) && !empty($file['tmp_name']) && ($file['tmp_name'] != 'none') && is_uploaded_file($file['tmp_name'])) { |
| 69 | 69 | if (sizeof($this->mime_types) > 0) { |
| 70 | 70 | if (!in_array(strtolower($file['type']), $this->mime_types)) { |
| 71 | | $messageStack->add_session(ERROR_FILETYPE_NOT_ALLOWED, 'error'); |
| | 71 | $this->set_message(ERROR_FILETYPE_NOT_ALLOWED); |
| 72 | 72 | return false; |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | if (sizeof($this->extensions) > 0) { |
| 76 | 76 | if (!in_array(strtolower(substr($file['name'], strrpos($file['name'], '.')+1)), $this->extensions)) { |
| 77 | | $messageStack->add_session(ERROR_FILETYPE_NOT_ALLOWED, 'error'); |
| | 77 | $this->set_message(ERROR_FILETYPE_NOT_ALLOWED); |
| 78 | 78 | return false; |
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | //BOF - DokuMan - 2010-08-31 - disable upload of php files and htaccess/htpasswd to avoid uploading of malicious scripts |
| | 82 | /* |
| 82 | 83 | if (in_array(strtolower(substr($file['name'], strrpos($file['name'], '.')+1)), array('php', 'php3', 'php4', 'php5', 'phtml'))) { |
| 83 | | $messageStack->add_session(ERROR_FILETYPE_NOT_ALLOWED, 'error'); |
| | 84 | $this->set_message(ERROR_FILETYPE_NOT_ALLOWED); |
| 84 | 85 | return false; |
| 85 | 86 | } |
| | 87 | */ |
| 86 | 88 | if ($file['name'] == '.htaccess' || $file['name'] == '.htpasswd') { |
| 87 | | $messageStack->add_session(ERROR_FILETYPE_NOT_ALLOWED, 'error'); |
| | 89 | $this->set_message(ERROR_FILETYPE_NOT_ALLOWED); |
| 88 | 90 | return false; |
| 89 | 91 | } |
| 90 | 92 | //EOF - DokuMan - 2010-08-31 - disable upload of php files and htaccess/htpasswd to avoid uploading of malicious scripts |
| … |
… |
defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'
|
| 95 | 97 | return $this->check_destination(); |
| 96 | 98 | |
| 97 | 99 | } else { |
| 98 | | if ($file['tmp_name']=='none') $messageStack->add_session(WARNING_NO_FILE_UPLOADED, 'warning'); |
| | 100 | if ($file['tmp_name']=='none') $this->set_message(WARNING_NO_FILE_UPLOADED, 'warning'); |
| 99 | 101 | return false; |
| 100 | 102 | } |
| 101 | 103 | } |
| 102 | 104 | |
| 103 | 105 | function save() { |
| 104 | | global $messageStack; |
| 105 | 106 | |
| 106 | 107 | if (substr($this->destination, -1) != '/') $this->destination .= '/'; |
| 107 | 108 | |
| … |
… |
defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'
|
| 114 | 115 | if (strstr(PRODUCT_IMAGE_THUMBNAIL_MERGE,'.gif') || |
| 115 | 116 | strstr(PRODUCT_IMAGE_INFO_MERGE,'.gif') || |
| 116 | 117 | strstr(PRODUCT_IMAGE_POPUP_MERGE,'.gif')) { |
| 117 | | $messageStack->add_session(ERROR_GIF_MERGE, 'error'); |
| | 118 | $this->set_message(ERROR_GIF_MERGE); |
| 118 | 119 | return false; |
| 119 | 120 | } |
| 120 | 121 | // check if uploaded image = .gif |
| 121 | 122 | if (strstr($this->filename,'.gif')) { |
| 122 | | $messageStack->add_session(ERROR_GIF_UPLOAD, 'error'); |
| | 123 | $this->set_message(ERROR_GIF_UPLOAD); |
| 123 | 124 | return false; |
| 124 | 125 | } |
| 125 | 126 | |
| … |
… |
defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'
|
| 129 | 130 | |
| 130 | 131 | if (move_uploaded_file($this->file['tmp_name'], $this->destination . $this->filename)) { |
| 131 | 132 | chmod($this->destination . $this->filename, $this->permissions); |
| 132 | | $messageStack->add_session(SUCCESS_FILE_SAVED_SUCCESSFULLY, 'success'); |
| | 133 | $this->set_message(SUCCESS_FILE_SAVED_SUCCESSFULLY, 'success'); |
| 133 | 134 | return true; |
| 134 | 135 | |
| 135 | 136 | } else { |
| 136 | | $messageStack->add_session(ERROR_FILE_NOT_SAVED, 'error'); |
| | 137 | $this->set_message(ERROR_FILE_NOT_SAVED); |
| 137 | 138 | return false; |
| 138 | 139 | } |
| 139 | 140 | } |
| … |
… |
defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'
|
| 170 | 171 | } |
| 171 | 172 | } |
| 172 | 173 | |
| | 174 | /** |
| | 175 | * Set mime types. |
| | 176 | * @since 2.0.1 |
| | 177 | * @param string|array $mime_types Mime type(string) or types(array). |
| | 178 | */ |
| | 179 | function set_mime_types($mime_types) { |
| | 180 | if (xtc_not_null($mime_types)) { |
| | 181 | if (is_array($mime_types)) { |
| | 182 | $this->mime_types = $mime_types; |
| | 183 | } else { |
| | 184 | $this->mime_types = array($mime_types); |
| | 185 | } |
| | 186 | } else { |
| | 187 | $this->mime_types = array(); |
| | 188 | } |
| | 189 | } |
| | 190 | |
| 173 | 191 | function check_destination() { |
| 174 | | global $messageStack; |
| 175 | 192 | |
| 176 | 193 | if (!is_writeable($this->destination)) { |
| 177 | 194 | if (is_dir($this->destination)) { |
| 178 | | $messageStack->add_session(sprintf(ERROR_DESTINATION_NOT_WRITEABLE, $this->destination), 'error'); |
| | 195 | $this->set_message(sprintf(ERROR_DESTINATION_NOT_WRITEABLE, $this->destination)); |
| 179 | 196 | } else { |
| 180 | | $messageStack->add_session(sprintf(ERROR_DESTINATION_DOES_NOT_EXIST, $this->destination), 'error'); |
| | 197 | $this->set_message(sprintf(ERROR_DESTINATION_DOES_NOT_EXIST, $this->destination)); |
| 181 | 198 | } |
| 182 | 199 | return false; |
| 183 | 200 | |
| … |
… |
defined( '_VALID_XTC' ) or die( 'Direct Access to this location is not allowed.'
|
| 186 | 203 | } |
| 187 | 204 | } |
| 188 | 205 | |
| | 206 | /** |
| | 207 | * Set message. |
| | 208 | * @since 2.0.1 |
| | 209 | * @param string $text Message text. |
| | 210 | * @param string $type (optional) Message type. |
| | 211 | */ |
| | 212 | private function set_message($text, $type = 'error') { |
| | 213 | global $messageStack; |
| | 214 | if (is_object($messageStack)) { |
| | 215 | $messageStack->add_session($text, $type); |
| | 216 | } |
| | 217 | } |
| | 218 | |
| 189 | 219 | } |
| 190 | | ?> |
| 191 | | No newline at end of file |