Example #1
0
 function set_profile_image()
 {
     $this->delete_existing_images($this->id);
     //save references to the upload paths
     $upload_path = get_config('uploads.user_images_path');
     $web_path = get_config('uploads.user_images_web_path');
     File::set_upload_headers();
     //make the directories for the user images if they do not exist
     if (!is_dir($upload_path)) {
         Utils::create_directory($upload_path);
     }
     if (!is_dir($upload_path . 'thumbs/')) {
         Utils::create_directory($upload_path . 'thumbs/');
     }
     //get the extension of the original image
     $ext = pathinfo($_FILES['files']['name'], PATHINFO_EXTENSION);
     //generate the filename for the image (user id + original extionsion) i.e. 1.jpg
     $name = isset($ext) && !empty($ext) ? "{$this->id}.{$ext}" : $this->id;
     //perform the upload
     $upload = new Upload(array('upload_dir' => $upload_path, 'upload_url' => $web_path, 'file_name' => $name, 'overwrite_existing' => true));
     $status = $upload->post();
     $status = $status[0];
     if ($status->size > 0) {
         //we need to resize the images, the large size, and the thumb size
         $this->resize($upload_path . "{$name}", $upload_path . "{$name}", 200, 100);
         $this->resize($upload_path . "{$name}", $upload_path . "thumbs/{$name}", 80, 90);
         return true;
     } else {
         return false;
     }
 }