Example #1
0
 public function profile($f3)
 {
     $id = $this->Auth->user('id');
     extract($this->request->data);
     $u = $this->Model->Users->fetch($id);
     if ($this->request->is('post')) {
         $u->copyfrom('POST');
         //Handle avatar upload
         if (isset($_FILES['avatar']) && isset($_FILES['avatar']['tmp_name']) && !empty($_FILES['avatar']['tmp_name'])) {
             $url = File::Upload($_FILES['avatar']);
             $u->avatar = $url;
         } else {
             if (isset($reset)) {
                 $u->avatar = '';
             }
         }
         $u->save();
         \StatusMessage::add('Profile updated succesfully', 'success');
         return $f3->reroute('/user/profile');
     }
     $_POST = $u->cast();
     $f3->set('u', $u);
 }
Example #2
0
 public function profile($f3)
 {
     $id = $this->Auth->user('id');
     extract($this->request->data);
     $u = $this->Model->Users->fetch($id);
     if ($this->request->is('post')) {
         $u->copyfrom('POST');
         //Handle avatar upload
         if (isset($_FILES['avatar']) && isset($_FILES['avatar']['tmp_name']) && !empty($_FILES['avatar']['tmp_name'])) {
             $allowedTypes = array(IMAGETYPE_PNG, IMAGETYPE_JPEG);
             $detectedType = exif_imagetype($_FILES['avatar']['tmp_name']);
             if (!in_array($detectedType, $allowedTypes) || $_FILES['avatar']['size'] > 2 * 1024 * 1024 || !getimagesize($_FILES['avatar']['tmp_name'])) {
                 \StatusMessage::add('Invalid image', 'danger');
                 return $f3->reroute('/user/profile');
             }
             $ext = end(explode(".", $_FILES['avatar']['name']));
             $_FILES['avatar']['name'] = "avatar_of_user_" . $id . "." . $ext;
             $url = File::Upload($_FILES['avatar']);
             $u->avatar = $url;
         } else {
             if (isset($reset)) {
                 $u->avatar = '';
             }
         }
         $u->save();
         \StatusMessage::add('Profile updated succesfully', 'success');
         return $f3->reroute('/user/profile');
     }
     $_POST = $u->cast();
     $f3->set('u', $u);
 }
Example #3
0
<?php

//Load framework
chdir("..");
$f3 = (require 'lib/base.php');
$f3->config('/config/config.cfg');
$f3->set('AUTOLOAD', 'controllers/; models/; helpers/; utility/;');
//Get editor details
$CKEditor = $_GET['CKEditor'];
$funcNum = $_GET['CKEditorFuncNum'];
//Initialise return values
$url = '';
$message = '';
//Process uploaded file
if (isset($_FILES['upload'])) {
    $url = File::Upload($_FILES['upload']);
    if (!$url) {
        $message = 'The upload failed';
    }
} else {
    $message = 'No file was uploaded';
}
//Return to CKEditor
echo "<script type='text/javascript'> window.parent.CKEDITOR.tools.callFunction({$funcNum}, '{$url}', '{$message}')</script>";