# fluent-support/trunk/app/Services/AvatarUploder.php

Fluent Support – Helpdesk &amp; Customer Support Ticket System, version trunk. 72 lines.

- Page: https://pluginprobe.com/plugins/fluent-support/trunk/code/app/Services/AvatarUploder.php
- Raw: https://pluginprobe.com/plugins/fluent-support/trunk/raw/app/Services/AvatarUploder.php
- Modified: 2026-02-05T14:04:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-support/trunk/code/app/Services/AvatarUploder.php#L10-L20`.

```php
<?php

namespace FluentSupport\App\Services;

use Exception;
use FluentSupport\App\Models\Agent;
use FluentSupport\App\Models\Customer;
use FluentSupport\App\Services\Includes\FileSystem;

class AvatarUploder
{
    /**
     * @param $file - file object
     * @param int $userid - user id
     * @param string $type - Customer or Agent
     * @throws Exception
     * @return array
     */
    public function addOrUpdateProfileImage ( $file, $userid, $type )
    {
        $this->validateExtension($file);

        $user = $type == 'customer'? Customer::findOrFail($userid) : Agent::findOrFail($userid);

        $uploadedImage = FileSystem::setSubDir(strtolower($type).'_avatars')->put($file);


        if ( !$uploadedImage ) {
            throw new Exception(esc_html__('Something went wrong while updating the profile picture', 'fluent-support'), 403);
        }

        $user->avatar = $uploadedImage[0]['url'];
        $user->save();

        return [
            'message' => __('Profile picture has been updated successfully', 'fluent-support'),
            'image'   => $user->avatar,
            $type     => $user
        ];
    }

    /**
     * This Method Will Validate The Extension Of The File
     * @param $file - file object
     * @throws Exception
     * @return bool
     */
    private function validateExtension($file)
    {
        /**
         * Filter profile picture upload types
         * @param array $allowedExtension
         */
        $allowedExtension = apply_filters('fluent_support/allowed_customer_profile_picture_file_type',
        array('jpeg', 'jpe', 'jpg', 'png'));

        $ext = $file['file']->getClientOriginalExtension();

        if( !in_array($ext, $allowedExtension) ) {
            throw new Exception(
                sprintf(
                    // translators: %s is a comma-separated list of allowed file extensions (e.g., "jpg, png, gif")
                    esc_html__('Unsupported file submitted, allowed image file types are: %s', 'fluent-support'),
                    esc_html(implode(", ", $allowedExtension))
                ), 403
            );
        }

        return true;
    }
}

```
