示例#1
0
 /**
  * @param array $params
  * @return bool
  */
 public function update($params = array())
 {
     // if not user id then we should not be doing anything here
     if (empty($params['user_id'])) {
         return false;
     }
     $this->user_id = $params['user_id'];
     // check for a previous avatar otherwise set the default
     $this->image = $params['current_avatar'];
     if (empty($this->image)) {
         $this->image = URL_FULL . 'framework/modules/users/assets/images/avatar_not_found.jpg';
     }
     if (!empty($_FILES['avatar']['tmp_name'])) {
         // if the user uploaded a new avatar lets save it!
         $info = expFile::getImageInfo($_FILES['avatar']['tmp_name']);
         if ($info['is_image']) {
             // figure out the mime type and set the file extension and name
             $extinfo = explode('/', $info['mime']);
             $extension = $extinfo[1];
             $avatar_name = $this->user_id . '.' . $extension;
             // save the file to the filesystem
             $file = expFile::fileUpload('avatar', true, false, $avatar_name, 'files/avatars/');
             //save the file to the database
             $this->image = $file->url;
             $this->use_gravatar = false;
             // if we uploaded a file, we don't want to use gravatar
         }
     } elseif (!empty($params['use_gravatar'])) {
         // if the user chose gravatar, create the link and save it!
         $this->use_gravatar = $params['use_gravatar'];
         $emailMD5 = md5(strtolower(trim(user::getEmailById($params['user_id']))));
         $this->image = "http://www.gravatar.com/avatar/" . $emailMD5 . ".jpg";
     }
     parent::update();
 }
示例#2
0
 public function upload()
 {
     // upload the file, but don't save the record yet...
     $file = expFile::fileUpload('Filedata', false, false);
     // since most likely this function will only get hit via flash in YUI Uploader
     // and since Flash can't pass cookies, we lose the knowledge of our $user
     // so we're passing the user's ID in as $_POST data. We then instantiate a new $user,
     // and then assign $user->id to $file->poster so we have an audit trail for the upload
     if (is_object($file)) {
         $user = new user($_REQUEST['usrid']);
         $file->poster = $user->id;
         $file->save();
         // a blank echo so YUI Uploader is notified of the function's completion
         echo ' ';
     } else {
         flash('error', gt('File was not uploaded!'));
     }
 }
示例#3
0
//Get the post data for future massaging
$post = $_POST;
//Check to make sure the user filled out the required input.
if (!is_numeric($_POST["rowstart"])) {
    unset($post['rowstart']);
    $post['_formError'] = gt('The starting row must be a number.');
    expSession::set("last_POST", $post);
    header("Location: " . $_SERVER['HTTP_REFERER']);
    exit('Redirecting...');
}
//Get the temp directory to put the uploaded file
$directory = "framework/modules-1/importer/importers/usercsv/tmp";
//Get the file save it to the temp directory
if ($_FILES["upload"]["error"] == UPLOAD_ERR_OK) {
    //	$file = file::update("upload",$directory,null,time()."_".$_FILES['upload']['name']);
    $file = expFile::fileUpload("upload", false, false, time() . "_" . $_FILES['upload']['name'], $directory);
    //FIXME quick hack to remove file model
    if ($file == null) {
        switch ($_FILES["upload"]["error"]) {
            case UPLOAD_ERR_INI_SIZE:
            case UPLOAD_ERR_FORM_SIZE:
                $post['_formError'] = gt('The file you attempted to upload is too large.  Contact your system administrator if this is a problem.');
                break;
            case UPLOAD_ERR_PARTIAL:
                $post['_formError'] = gt('The file was only partially uploaded.');
                break;
            case UPLOAD_ERR_NO_FILE:
                $post['_formError'] = gt('No file was uploaded.');
                break;
            default:
                $post['_formError'] = gt('A strange internal error has occurred.  Please contact the Exponent Developers.');