Neuron-PHP

CloudinaryUploader
in package
implements IMediaUploader

Cloudinary implementation of media uploader.

Handles file uploads and deletions using Cloudinary service.

Table of Contents

Interfaces

IMediaUploader
Interface for media upload services.

Properties

$_cloudinary  : Cloudinary
$_settings  : SettingManager

Methods

__construct()  : mixed
Constructor
delete()  : bool
Delete a file by its public ID
listResources()  : array<string|int, mixed>
List resources from Cloudinary
upload()  : array<string|int, mixed>
Upload a file from local filesystem
uploadFromUrl()  : array<string|int, mixed>
Upload a file from URL
buildUploadOptions()  : array<string|int, mixed>
Build upload options by merging user options with config defaults
formatResult()  : array<string|int, mixed>
Format Cloudinary result into standardized array
initializeCloudinary()  : Cloudinary
Initialize Cloudinary instance
isPrivateOrReservedIp()  : bool
Check if an IP address is private, loopback, link-local, or reserved
resolveHostnameToIps()  : array<string|int, mixed>
Resolve hostname to IP addresses (both IPv4 and IPv6)
validateUrlAgainstSsrf()  : void
Validate URL against SSRF (Server-Side Request Forgery) attacks

Properties

Methods

delete()

Delete a file by its public ID

public delete(string $publicId) : bool
Parameters
$publicId : string

The public ID of the file to delete

Tags
throws
Exception

If deletion fails

Return values
bool

True if deletion was successful

listResources()

List resources from Cloudinary

public listResources([array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed> = []

Options for listing (max_results, next_cursor, prefix, etc.)

Tags
throws
Exception

If listing fails

Return values
array<string|int, mixed>

Resources list with pagination info

upload()

Upload a file from local filesystem

public upload(string $filePath[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
Parameters
$filePath : string

Path to the file to upload

$options : array<string|int, mixed> = []

Upload options (folder, transformation, etc.)

Tags
throws
Exception

If upload fails

Return values
array<string|int, mixed>

Upload result with keys: url, public_id, width, height, format

uploadFromUrl()

Upload a file from URL

public uploadFromUrl(string $url[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
Parameters
$url : string

URL of the file to upload

$options : array<string|int, mixed> = []

Upload options (folder, transformation, etc.)

Tags
throws
Exception

If upload fails or URL is unsafe

Return values
array<string|int, mixed>

Upload result with keys: url, public_id, width, height, format

buildUploadOptions()

Build upload options by merging user options with config defaults

private buildUploadOptions(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed>

User-provided options

Return values
array<string|int, mixed>

Complete upload options

formatResult()

Format Cloudinary result into standardized array

private formatResult(array<string|int, mixed> $result) : array<string|int, mixed>
Parameters
$result : array<string|int, mixed>

Cloudinary upload result

Return values
array<string|int, mixed>

Formatted result

initializeCloudinary()

Initialize Cloudinary instance

private initializeCloudinary() : Cloudinary
Tags
throws
Exception

If configuration is invalid

Return values
Cloudinary

isPrivateOrReservedIp()

Check if an IP address is private, loopback, link-local, or reserved

private isPrivateOrReservedIp(string $ip) : bool

Blocks the following ranges:

  • Private IPv4: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16
  • Loopback IPv4: 127.0.0.0/8
  • Link-local IPv4: 169.254.0.0/16
  • Loopback IPv6: ::1
  • Private IPv6: fc00::/7
  • Link-local IPv6: fe80::/10
  • IPv4-mapped IPv6: ::ffff:0:0/96
Parameters
$ip : string

The IP address to check

Return values
bool

True if IP is private/reserved, false otherwise

resolveHostnameToIps()

Resolve hostname to IP addresses (both IPv4 and IPv6)

private resolveHostnameToIps(string $hostname) : array<string|int, mixed>
Parameters
$hostname : string

The hostname to resolve

Return values
array<string|int, mixed>

Array of IP addresses

validateUrlAgainstSsrf()

Validate URL against SSRF (Server-Side Request Forgery) attacks

private validateUrlAgainstSsrf(string $url) : void

Ensures the URL:

  • Is a valid URL
  • Uses HTTPS protocol only
  • Does not resolve to private/internal IP addresses
  • Does not target loopback, link-local, or cloud metadata addresses
Parameters
$url : string

The URL to validate

Tags
throws
Exception

If URL is invalid or unsafe


        
On this page

Search results