[ Index ] |
|
Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1 |
1 <?php 2 // 3 // +----------------------------------------------------------------------+ 4 // |zen-cart Open Source E-commerce | 5 // +----------------------------------------------------------------------+ 6 // | Copyright (c) 2003 The zen-cart developers | 7 // | | 8 // | http://www.zen-cart.com/index.php | 9 // | | 10 // | Portions Copyright (c) 2003 osCommerce | 11 // +----------------------------------------------------------------------+ 12 // | This source file is subject to version 2.0 of the GPL license, | 13 // | that is bundled with this package in the file LICENSE, and is | 14 // | available through the world-wide-web at the following url: | 15 // | http://www.zen-cart.com/license/2_0.txt. | 16 // | If you did not receive a copy of the zen-cart license and are unable | 17 // | to obtain it through the world-wide-web, please send a note to | 18 // | license@zen-cart.com so we can mail you a copy immediately. | 19 // +----------------------------------------------------------------------+ 20 // $Id: upload.php 1969 2005-09-13 06:57:21Z drbyte $ 21 // 22 23 class upload { 24 var $file, $filename, $destination, $permissions, $extensions, $tmp_filename, $message_location; 25 26 function upload($file = '', $destination = '', $permissions = '777', $extensions = '') { 27 $this->set_file($file); 28 $this->set_destination($destination); 29 $this->set_permissions($permissions); 30 $this->set_extensions($extensions); 31 32 $this->set_output_messages('direct'); 33 34 if (zen_not_null($this->file) && zen_not_null($this->destination)) { 35 $this->set_output_messages('session'); 36 37 if ( ($this->parse() == true) && ($this->save() == true) ) { 38 return true; 39 } else { 40 // self destruct 41 while(list($key,) = each($this)) { 42 $this->$key = null; 43 } 44 45 return false; 46 } 47 } 48 } 49 50 function parse() { 51 global $messageStack; 52 53 if (isset($_FILES[$this->file])) { 54 $file = array('name' => $_FILES[$this->file]['name'], 55 'type' => $_FILES[$this->file]['type'], 56 'size' => $_FILES[$this->file]['size'], 57 'tmp_name' => $_FILES[$this->file]['tmp_name']); 58 } elseif (isset($GLOBALS['HTTP_POST_FILES'][$this->file])) { 59 global $HTTP_POST_FILES; 60 61 $file = array('name' => $HTTP_POST_FILES[$this->file]['name'], 62 'type' => $HTTP_POST_FILES[$this->file]['type'], 63 'size' => $HTTP_POST_FILES[$this->file]['size'], 64 'tmp_name' => $HTTP_POST_FILES[$this->file]['tmp_name']); 65 } else { 66 $file = array('name' => (isset($GLOBALS[$this->file . '_name']) ? $GLOBALS[$this->file . '_name'] : ''), 67 'type' => (isset($GLOBALS[$this->file . '_type']) ? $GLOBALS[$this->file . '_type'] : ''), 68 'size' => (isset($GLOBALS[$this->file . '_size']) ? $GLOBALS[$this->file . '_size'] : ''), 69 'tmp_name' => (isset($GLOBALS[$this->file]) ? $GLOBALS[$this->file] : '')); 70 } 71 72 if ( zen_not_null($file['tmp_name']) && ($file['tmp_name'] != 'none') && is_uploaded_file($file['tmp_name']) ) { 73 if (sizeof($this->extensions) > 0) { 74 if (!in_array(strtolower(substr($file['name'], strrpos($file['name'], '.')+1)), $this->extensions)) { 75 if ($this->message_location == 'direct') { 76 $messageStack->add(ERROR_FILETYPE_NOT_ALLOWED, 'error'); 77 } else { 78 $messageStack->add_session(ERROR_FILETYPE_NOT_ALLOWED, 'error'); 79 } 80 81 return false; 82 } 83 } 84 85 $this->set_file($file); 86 $this->set_filename($file['name']); 87 $this->set_tmp_filename($file['tmp_name']); 88 89 return $this->check_destination(); 90 } else { 91 if ($file['name'] !='' && $file['tmp_name'] !='') { 92 if ($this->message_location == 'direct') { 93 $messageStack->add(WARNING_NO_FILE_UPLOADED, 'warning'); 94 } else { 95 $messageStack->add_session(WARNING_NO_FILE_UPLOADED, 'warning'); 96 } 97 } 98 return false; 99 } 100 } 101 102 function save($overwrite=true) { 103 global $messageStack; 104 105 if (!$overwrite and file_exists($this->destination . $this->filename)) { 106 $messageStack->add_session(TEXT_IMAGE_OVERWRITE_WARNING . $this->filename, 'caution'); 107 return true; 108 } else { 109 110 if (substr($this->destination, -1) != '/') $this->destination .= '/'; 111 112 if (move_uploaded_file($this->file['tmp_name'], $this->destination . $this->filename)) { 113 chmod($this->destination . $this->filename, $this->permissions); 114 115 if ($this->message_location == 'direct') { 116 $messageStack->add(sprintf(SUCCESS_FILE_SAVED_SUCCESSFULLY,$this->filename), 'success'); 117 } else { 118 $messageStack->add_session(sprintf(SUCCESS_FILE_SAVED_SUCCESSFULLY,$this->filename), 'success'); 119 } 120 121 return true; 122 } else { 123 if ($this->message_location == 'direct') { 124 $messageStack->add(ERROR_FILE_NOT_SAVED, 'error'); 125 } else { 126 $messageStack->add_session(ERROR_FILE_NOT_SAVED, 'error'); 127 } 128 129 return false; 130 } 131 } 132 } 133 134 function set_file($file) { 135 $this->file = $file; 136 } 137 138 function set_destination($destination) { 139 $this->destination = $destination; 140 } 141 142 function set_permissions($permissions) { 143 $this->permissions = octdec($permissions); 144 } 145 146 function set_filename($filename) { 147 $this->filename = $filename; 148 } 149 150 function set_tmp_filename($filename) { 151 $this->tmp_filename = $filename; 152 } 153 154 function set_extensions($extensions) { 155 if (zen_not_null($extensions)) { 156 if (is_array($extensions)) { 157 $this->extensions = $extensions; 158 } else { 159 $this->extensions = array($extensions); 160 } 161 } else { 162 $this->extensions = array(); 163 } 164 } 165 166 function check_destination() { 167 global $messageStack; 168 169 if (!is_writeable($this->destination)) { 170 if (is_dir($this->destination)) { 171 if ($this->message_location == 'direct') { 172 $messageStack->add_session(sprintf(ERROR_DESTINATION_NOT_WRITEABLE, $this->destination), 'error'); 173 } else { 174 $messageStack->add_session(sprintf(ERROR_DESTINATION_NOT_WRITEABLE, $this->destination), 'error'); 175 } 176 } else { 177 if ($this->message_location == 'direct') { 178 $messageStack->add(sprintf(ERROR_DESTINATION_DOES_NOT_EXIST, $this->destination), 'error'); 179 } else { 180 $messageStack->add_session(sprintf(ERROR_DESTINATION_DOES_NOT_EXIST, $this->destination), 'error'); 181 } 182 } 183 184 return false; 185 } else { 186 return true; 187 } 188 } 189 190 function set_output_messages($location) { 191 switch ($location) { 192 case 'session': 193 $this->message_location = 'session'; 194 break; 195 case 'direct': 196 default: 197 $this->message_location = 'direct'; 198 break; 199 } 200 } 201 } 202 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 16:45:43 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |