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; } }