Documentation

File
in package

Weaver Framework - File Handling Class

This class provides methods for uploading, writing, and reading files, along with error handling.

Table of Contents

Methods

readFile()  : string|false
Read file content.
uploadFile()  : array<string|int, mixed>
Upload a file with allowed file type check.
writeFile()  : bool
Write content to a file (create if not exists).

Methods

readFile()

Read file content.

public static readFile(string $filePath) : string|false
Parameters
$filePath : string

The path to the file.

Return values
string|false

The file content as a string, or false if the file does not exist.

uploadFile()

Upload a file with allowed file type check.

public static uploadFile(array<string|int, mixed> $fileHandle, string $uploadPath, array<string|int, mixed> $allowedFileTypes[, int|null $maxFileSize = null ]) : array<string|int, mixed>
Parameters
$fileHandle : array<string|int, mixed>

The file handle received from the file input field.

$uploadPath : string

The directory where the file will be uploaded.

$allowedFileTypes : array<string|int, mixed>

An array of allowed file extensions (e.g., ['jpg', 'png']).

$maxFileSize : int|null = null

(Optional) The maximum file size in MB (null for no limit).

Return values
array<string|int, mixed>

An array containing upload status, message, and uploaded file path.

writeFile()

Write content to a file (create if not exists).

public static writeFile(string $filePath, string $content) : bool
Parameters
$filePath : string

The path to the file.

$content : string

The content to write to the file.

Return values
bool

True on success, throws an exception on failure.


        
On this page

Search results