Changeset 253


Ignore:
Timestamp:
03/18/09 13:45:04 (3 years ago)
Author:
aarkerio
Message:

Avtars update

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/controllers/images_controller.php

    r245 r253  
    6464 { 
    6565  $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']);  
    7172     
    7273    /** SUBMITTED INFORMATION - use what you need 
     
    7677    *  mime-type of uploaded file  : $imgfile_type 
    7778    */ 
    78      
     79      
    7980    /** uploaddir:  directory relative to where script is running */ 
    8081     
     
    8990    /** Security: checks to see if file is an image, if not do not allow upload ==*/ 
    9091     
    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? */ 
    9394        $msg   = "ERROR the file $imgfile_name $imgfile is not valid. Only .jpg, .gif or .png files Current type file: " . $type ;     
    9495        /** delete uploaded file  */ 
     
    9697        $this->flash($msg,'/admin/images/listing/'); 
    9798        exit(); 
    98     } 
     99    endif; 
    99100     
    100101    if ( $imgfile_size > $maxfilesize): 
     
    106107    endif; 
    107108    $current_id  = (int) $this->Image->field('Image.id', null, 'id DESC'); 
    108     $next_id     = ($current_id + 1); 
    109      
     109    $next_id     = ($current_id + 1);     
    110110    $extension   = $this->Adds->get_extension($type); 
    111      
    112111    $name        = $this->Auth->user('username') . "_" . $next_id . $extension; 
    113112     
     
    121120    if (is_uploaded_file($imgfile)): 
    122121       /** 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/'); 
    128125        endif; 
    129         endif; 
     126   endif; 
    130127    
    131128   /*** Create thumb***/ 
     
    144141    /** delete the temporary uploaded file **/ 
    145142    unlink($imgfile); 
    146    } 
    147143 } 
    148144 
  • trunk/controllers/users_controller.php

    r242 r253  
    194194 public function admin_avatar()  
    195195 { 
    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 
    207202     
    208203    /** SUBMITTED INFORMATION - use what you need 
     
    214209     
    215210    /** uploaddir:  directory relative to where script is running */ 
    216     $uploaddir    = "../webroot/img/avatars"; 
    217      
     211    $uploaddir    = '../webroot/img/avatars'; 
    218212    $maxfilesize  = 2097152; /** 2MB max size */ 
    219213     
    220214    $imgfile_name = $this->data['User']['file']['name']; 
    221      
    222215    $imgfile_size = $this->data['User']['file']['size']; 
    223      
    224216    $imgfile      = $this->data['User']['file']['tmp_name']; 
    225            
    226217    $type         = $this->data['User']['file']['type']; 
    227218     
    228219    /** Security: checks to see if file is an image, if not do not allow upload ==*/ 
    229220     
    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; 
    236224        /** delete uploaded file  */ 
    237225        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;         
    247231         /** delete uploaded file */ 
    248232         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; 
    255239          
    256240    /** setup final file location and name */ 
    257241    /** change spaces to underscores in filename  */ 
    258     $final_filename = str_replace(" ", "_", $Name); 
     242    $final_filename = str_replace(" ", "_", $name); 
    259243    //die($final_filename); 
    260244    $newfile = $uploaddir . "/" . $final_filename; 
    261245     
    262246    /** 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)): 
    278257            $this->msgFlash('Data saved', '/admin/users/edit/'); 
    279258   endif; 
    280259          
    281         /** delete the temporary uploaded file **/ 
     260  /** delete the temporary uploaded file **/ 
    282261   unlink($imgfile); 
    283     
    284    } 
    285 } 
     262  } 
    286263} 
    287264?> 
Note: See TracChangeset for help on using the changeset viewer.