Changeset 253
- Timestamp:
- 03/18/09 13:45:04 (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
controllers/images_controller.php (modified) (7 diffs)
-
controllers/users_controller.php (modified) (2 diffs)
-
webroot/img/avatars/aarkerio_avatar.jpg (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
trunk/controllers/images_controller.php
r245 r253 64 64 { 65 65 $this->layout = 'admin'; 66 if (!empty($this->data) && is_uploaded_file($this->data['Image']['file']['tmp_name'])) 67 { 68 // echo "tmp_name : ". $this->data['Image']['file']['tmp_name'] . "<br />"; // usefull print 69 70 $this->data['Image'] = Sanitize::clean($this->data['Image']); 66 67 if ($this->data['Image']['file']['error'] == 1): 68 $this->flash('Error uploading image, please contact the support team', '/admin/images/listing'); 69 endif; 70 71 $this->data['Image'] = Sanitize::clean($this->data['Image']); 71 72 72 73 /** SUBMITTED INFORMATION - use what you need … … 76 77 * mime-type of uploaded file : $imgfile_type 77 78 */ 78 79 79 80 /** uploaddir: directory relative to where script is running */ 80 81 … … 89 90 /** Security: checks to see if file is an image, if not do not allow upload ==*/ 90 91 91 if ( $type != "image/jpeg" && $type != "image/pjpeg" && $type != "image/png" && $type != "image/gif") 92 {/** is this a valid file? */92 if ( $type != "image/jpeg" && $type != "image/pjpeg" && $type != "image/png" && $type != "image/gif"): 93 /** is this a valid file? */ 93 94 $msg = "ERROR the file $imgfile_name $imgfile is not valid. Only .jpg, .gif or .png files Current type file: " . $type ; 94 95 /** delete uploaded file */ … … 96 97 $this->flash($msg,'/admin/images/listing/'); 97 98 exit(); 98 }99 endif; 99 100 100 101 if ( $imgfile_size > $maxfilesize): … … 106 107 endif; 107 108 $current_id = (int) $this->Image->field('Image.id', null, 'id DESC'); 108 $next_id = ($current_id + 1); 109 109 $next_id = ($current_id + 1); 110 110 $extension = $this->Adds->get_extension($type); 111 112 111 $name = $this->Auth->user('username') . "_" . $next_id . $extension; 113 112 … … 121 120 if (is_uploaded_file($imgfile)): 122 121 /** move file to proper directory ==*/ 123 if (!copy($imgfile, $newfile)): 124 /** if an error occurs the file could not 125 be written, read or possibly does not exist ==*/ 126 127 $this->flash('Error Uploading File.', '/admin/images/listing/'); 122 if (!move_uploaded_file($imgfile, $newfile)): 123 /** if an error occurs the file could not be written, read or possibly does not exist ==*/ 124 $this->flash('Error moving uploaded File.', '/admin/images/listing/'); 128 125 endif; 129 endif;126 endif; 130 127 131 128 /*** Create thumb***/ … … 144 141 /** delete the temporary uploaded file **/ 145 142 unlink($imgfile); 146 }147 143 } 148 144 -
trunk/controllers/users_controller.php
r242 r253 194 194 public function admin_avatar() 195 195 { 196 //die(print_r($this->params)); 197 $this->layout = 'admin'; 198 199 if (!empty($this->data) && is_uploaded_file($this->data['User']['file']['tmp_name'])) 200 { 201 202 // echo "tmp_name : ". $this->data['User']['file']['tmp_name'] . "<br />"; // usefull print 203 204 205 206 Sanitize::clean($this->data); //Hopefully this is enough 196 //die(print_r($this->data)); 197 $this->layout = 'admin'; 198 if (!empty($this->data) && is_uploaded_file($this->data['User']['file']['tmp_name'])): 199 $this->flash('Error uploading image, please contact the support team', '/admin/users/edit'); 200 endif; 201 #Sanitize::clean($this->data); //Hopefully this is enough 207 202 208 203 /** SUBMITTED INFORMATION - use what you need … … 214 209 215 210 /** uploaddir: directory relative to where script is running */ 216 $uploaddir = "../webroot/img/avatars"; 217 211 $uploaddir = '../webroot/img/avatars'; 218 212 $maxfilesize = 2097152; /** 2MB max size */ 219 213 220 214 $imgfile_name = $this->data['User']['file']['name']; 221 222 215 $imgfile_size = $this->data['User']['file']['size']; 223 224 216 $imgfile = $this->data['User']['file']['tmp_name']; 225 226 217 $type = $this->data['User']['file']['type']; 227 218 228 219 /** Security: checks to see if file is an image, if not do not allow upload ==*/ 229 220 230 if ( $type != "image/jpeg" && $type != "image/pjpeg" && $type != "image/png" && $type != "image/gif") 231 { /** is this a valid file? */ 232 $ErrMsg = "<h1>ERROR</h1> the file $imgfile_name $imgfile is not valid.<br>"; 233 $ErrMsg .= "<p>Only .jpg, .gif or .png files<br><br>"; 234 $ErrMsg .= "Current type file: " . $type . "</p>\n"; 235 221 if ( $type != "image/jpeg" && $type != "image/pjpeg" && $type != "image/png" && $type != "image/gif"): 222 /** is this a valid file? */ 223 $msg = "ERROR the file is not valid. Only .jpg, .gif or .png files Current type file: " . $type; 236 224 /** delete uploaded file */ 237 225 unlink($imgfile); 238 die($this->flash($ErrMsg, '/users/edit/'. $this->Auth->user('id')) ); 239 } 240 241 if ( $imgfile_size > $maxfilesize) 242 { 243 $ErrMsg = "<h1>ERROR</h1> The image is too big.<br>"; 244 $ErrMsg .= "<p>Bigger than 2.0 MB <br><br>"; 245 $ErrMsg .= "Current size: " . $imgfile_size ."</p>\n"; 246 226 die($this->flash($msg, '/users/edit/'. $this->Auth->user('id')) ); 227 endif; 228 229 if ( $imgfile_size > $maxfilesize): 230 $msg = "ERROR The image is too big. Bigger than 2.0 MB Current size: " . $imgfile_size; 247 231 /** delete uploaded file */ 248 232 unlink($imgfile); 249 die( $this->flash($ ErrMsg,'/users/edit/'.$this->Auth->user('id')) );250 }251 252 $extension = $this-> get_extension($type);253 254 $Name = $this->Auth->user('username') . "_avatar" . $extension;233 die( $this->flash($msg,'/users/edit/'.$this->Auth->user('id')) ); 234 endif; 235 236 $extension = $this->Adds->get_extension($type); 237 238 $name = $this->Auth->user('username') . "_avatar" . $extension; 255 239 256 240 /** setup final file location and name */ 257 241 /** change spaces to underscores in filename */ 258 $final_filename = str_replace(" ", "_", $ Name);242 $final_filename = str_replace(" ", "_", $name); 259 243 //die($final_filename); 260 244 $newfile = $uploaddir . "/" . $final_filename; 261 245 262 246 /** do extra security check to prevent malicious abuse */ 263 if (is_uploaded_file($imgfile)) 264 { 265 /** move file to proper directory ==*/ 266 if (!copy($imgfile, $newfile)) 267 { 268 /** if an error occurs the file could not be written, read or possibly does not exist */ 269 die($this->flash('Error Uploading File.', '/users/edit/'.$this->Auth->user('id'))); 270 } 271 } 272 273 /** Database stuff **/ 274 275 $this->data['User']['avatar'] = $final_filename; 276 277 if ($this->User->save($this->data)): 247 if (is_uploaded_file($imgfile)): 248 /** move file to proper directory ==*/ 249 if ( !move_uploaded_file($imgfile, $newfile) ): 250 /** if an error occurs the file could not be written, read or possibly does not exist */ 251 die($this->flash('Error Uploading File.', '/users/edit/'.$this->Auth->user('id'))); 252 endif; 253 endif; 254 255 /** Now the database stuff **/ 256 if ($this->User->saveField('avatar', $final_filename)): 278 257 $this->msgFlash('Data saved', '/admin/users/edit/'); 279 258 endif; 280 259 281 /** delete the temporary uploaded file **/260 /** delete the temporary uploaded file **/ 282 261 unlink($imgfile); 283 284 } 285 } 262 } 286 263 } 287 264 ?>
Note: See TracChangeset
for help on using the changeset viewer.
