RISE has one image upload control for profile pictures, logos and icons. Use it in your plugin when a form needs an image. It shows a button with two options: Upload and crop and Upload with the required size.
Show the control
Put it inside the form that saves the image. Add a preview image with its own id.
<?php echo view("includes/image_upload", array( "name" => "my_logo", "width" => 300, "height" => 100, "preview" => "#my-logo-preview" )); ?>
The crop box is added for you. The control works in full pages and in modal forms.
| Parameter | What it does |
| name | Field name. Required. The form posts name (the cropped image) or name_file (the uploaded file). |
| width, height | Image size in px. Default 200 x 200. The size is shown in the menu, and an uploaded file must have this size. Use 0 for any size (like logos): the crop frame fits the whole image, and an uploaded image of any size is accepted. |
| preview | Selector of the preview image. Default #name-preview. |
| auto_submit | true = submit the form right after an image is chosen. Default false. |
| button | default = a normal Upload button. icon = a round camera button for the corner of an avatar. |
| button_text | Text of the default button. |
| crop, direct | false hides Upload and crop or Upload. |
| default_image | URL of the default image. Shows a Remove picture option, which posts name = remove. |
For a small avatar with the camera button on its corner, wrap the image and the control in In a controller that extends Security_Controller: It returns the file info to save in the database, or an empty text when no image was posted. When the uploaded file is not an image of the right size, it sends an error to the form and stops. Pass 0, 0 as the size to accept an image of any size. Team members, client contacts and lead contacts use the same profile header: users/profile_header. The old view users/profile_image_section was removed. To save a user's picture from your own controller, check the access first, then call $this->save_user_profile_image($user_info). To show an AI agent's picture, use get_ai_agent_avatar($agent->image, $agent->ai_service). It returns the agent's picture, or the logo of its AI service when it has none.Save the image
$image = $this->get_posted_image_file("my_logo", get_setting("system_file_path"), "my-logo.png", 300, 100);
if ($image) {
//save $image in your table, delete the old file with delete_app_files()
}
Profile pictures
AI agent pictures