File
File
Properties
sourceFile
public string $sourceFiledefaultCipher
public string $defaultCipher = 'aes-256-ctr'defaultKey
public string $defaultKey = 'hazaar_secret_badass_key'manager
protected Manager $managerinfo
protected array $infomimeContentType
public string $mimeContentTypecontents
Any overridden file contents.
protected string $contentsThis is normally used when performing operations on the file in memory, such as resizing an image.
csvContents
public array $csvContentsresource
protected mixed $resourcerelativePath
public string $relativePathstream
private mixed $streamencrypted
private bool $encrypted__media_url
public URL $__media_urlfilters
Content filters.
private array $filtersMethods
__construct
public __construct(mixed $file, ?Manager $manager, ?string $relativePath): voidParameters
| Parameter | Type | Description |
|---|---|---|
$file | mixed | |
$manager | Manager | |
$relativePath | string |
__toString
public __toString(): stringbackend
public backend(): stringgetManager
public getManager(): Managerget
public get(string $url, ?Client $client): FileParameters
| Parameter | Type | Description |
|---|---|---|
$url | string | |
$client | Client |
registerFilter
Content filters.
public registerFilter(int $type, string $callable): boolParameters
| Parameter | Type | Description |
|---|---|---|
$type | int | |
$callable | string |
setMeta
public setMeta(array $values): boolParameters
| Parameter | Type | Description |
|---|---|---|
$values | array |
getMeta
public getMeta(?string $key): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$key | string |
toString
public toString(): stringbaseName
public baseName(string $suffix): stringParameters
| Parameter | Type | Description |
|---|---|---|
$suffix | string |
dirName
public dirName(): stringname
public name(): stringfullPath
public fullPath(): stringrelativePath
Get the relative path of the file.
public relativePath(NULL $path): voidIf the file was returned from a Hazaar\File\Dir object, then it will have a stored relative path. Otherwise any file/path can be provided in the form of another Hazaar\File object, Hazaar\File\Dir object, or string path, and the relative path to the file will be returned.
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | NULL | optional path to use as the relative path |
setRelativePath
public setRelativePath(string $path): voidParameters
| Parameter | Type | Description |
|---|---|---|
$path | string |
extension
public extension(): stringsize
public size(): ?intexists
public exists(): boolrealPath
public realPath(): stringisReadable
public isReadable(): boolisWritable
public isWritable(): boolisFile
public isFile(): boolisDir
public isDir(): boolisLink
public isLink(): booldir
public dir(): ?Dirparent
public parent(): Dirtype
public type(): ?stringctime
public ctime(): ?intmtime
public mtime(): ?inttouch
public touch(): boolatime
public atime(): ?inthasContents
public hasContents(): boolgetContents
Returns the current contents of the file.
public getContents(int $offset = -1, ?int $maxlen): stringParameters
| Parameter | Type | Description |
|---|---|---|
$offset | int | |
$maxlen | int |
putContents
Put contents directly writes data to the storage backend without storing it in the file object itself.
public putContents(string $data, bool $overwrite = true): ?intNOTE: This function is called internally to save data that has been updated in the file object.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | string | The data to write |
$overwrite | bool | Overwrite data if it exists |
setContents
Sets the current contents of the file in memory.
public setContents(?string $bytes): ?intCalling this function does not directly update the content of the file "on disk". To do that you must call the File::save() method which will commit the data to storage.
Parameters
| Parameter | Type | Description |
|---|---|---|
$bytes | string | The data to set as the content |
setDecodedContents
Set the contents from an encoded string.
public setDecodedContents(string $bytes): boolCurrently this supports only data URI encoded strings. I have made this generic in case I come across other types of encodings that will work with this method.
Parameters
| Parameter | Type | Description |
|---|---|---|
$bytes | string |
getEncodedContents
Return the contents of the file as a data URI encoded string.
public getEncodedContents(): voidThis function is basically the opposite of Hazaar\File::set_decoded_contents() and will generate a data URI based on the current MIME content type and the contents of the file.
save
Saves the current in-memory content to the storage backend.
public save(): ?intInternally this calls File::putContents() to write the data to the backend.
saveAs
Saves this file objects content to another file name.
public saveAs(string $filename, bool $overwrite): ?intParameters
| Parameter | Type | Description |
|---|---|---|
$filename | string | The filename to save as |
$overwrite | bool | Boolean flag to indicate that the destination should be overwritten if it exists |
unlink
Deletes the file from storage.
public unlink(): boolmd5
Generate an MD5 checksum of the current file content.
public md5(): stringbase64
Return the base64 encoded content.
public base64(): stringparseJSON
Returns the contents as decoded JSON.
public parseJSON(bool $assoc, \stdClass $): voidIf the content is a JSON encoded string, this will decode the string and return it as a stdClass object, or an associative array if the $assoc parameter is TRUE.
If the content can not be decoded because it is not a valid JSON string, this method will return FALSE.
Parameters
| Parameter | Type | Description |
|---|---|---|
$assoc | bool | Return as an associative array. Default is to use stdClass. |
$ | \stdClass |
moveTo
public moveTo(string $destination, bool $overwrite, bool $createDest, ?Manager $dstManager): FileParameters
| Parameter | Type | Description |
|---|---|---|
$destination | string | |
$overwrite | bool | |
$createDest | bool | |
$dstManager | Manager |
copyTo
Copy the file to another folder.
public copyTo(string $destination, bool $overwrite, bool $createDest, ?Manager $dstManager): FileThis differs to copy() which expects the target to be the full new file pathname.
Parameters
| Parameter | Type | Description |
|---|---|---|
$destination | string | The destination folder to copy the file into |
$overwrite | bool | overwrite the destination file if it exists |
$createDest | bool | Flag that indicates if the destination folder should be created. If the destination does not exist an error will be thrown. |
$dstManager | Manager | The destination file manager. Defaults to the same manager as the source. |
copy
Copy the file to another folder and filename.
public copy(string $destination, boolean $overwrite, boolean $createDest, NULL $dstManager): FileThis differs from copyTo which expects the target to be a folder
Parameters
| Parameter | Type | Description |
|---|---|---|
$destination | string | The destination folder and file name to copy the file into |
$overwrite | boolean | overwrite the destination file if it exists |
$createDest | boolean | Flag that indicates if the destination folder should be created. If the destination does not exist an error will be thrown. |
$dstManager | NULL | The destination file manager. Defaults to the same manager as the source. |
mimeContentType
public mimeContentType(): ?stringsetMimeContentType
public setMimeContentType(string $type): voidParameters
| Parameter | Type | Description |
|---|---|---|
$type | string |
thumbnailURL
public thumbnailURL(int $width = 100, int $height = 100, string $format = 'jpeg', array $params): ?stringParameters
| Parameter | Type | Description |
|---|---|---|
$width | int | |
$height | int | |
$format | string | |
$params | array |
previewURL
public previewURL(array $params): ?stringParameters
| Parameter | Type | Description |
|---|---|---|
$params | array |
directURL
public directURL(): ?stringmediaURL
public mediaURL(URL $setPath): URLParameters
| Parameter | Type | Description |
|---|---|---|
$setPath | URL |
toArray
public toArray(string $delimiter = '"\n"'): voidParameters
| Parameter | Type | Description |
|---|---|---|
$delimiter | string |
readCSV
Return the CSV content as a parsed array.
public readCSV(bool $useHeader_row): voidParameters
| Parameter | Type | Description |
|---|---|---|
$useHeader_row | bool | Indicates if a header row should be parsed and used to build an associative array. In this case the keys in the returned array will be the values from the first row, which is normally a header row. |
getCSV
Returns a line from the file pointer and parse for CSV fields.
public getCSV(int $length, string $delimiter = ',', string $enclosure = '"', string $escape = '\\'): voidParameters
| Parameter | Type | Description |
|---|---|---|
$length | int | Must be greater than the longest line (in characters) to be found in the CSV file (allowing for trailing line-end characters). Otherwise the line is split in chunks of length characters, unless the split would occur inside an enclosure. Omitting this parameter (or setting it to 0 in PHP 5.1.0 and later) the maximum line length is not limited, which is slightly slower. |
$delimiter | string | the optional delimiter parameter sets the field delimiter (one character only) |
$enclosure | string | the optional enclosure parameter sets the field enclosure character (one character only) |
$escape | string | the optional escape parameter sets the escape character (one character only) |
putCSV
Writes an array to the file in CSV format.
public putCSV(array $fields, string $delimiter = ',', string $enclosure = '"', string $escape = '\\'): voidParameters
| Parameter | Type | Description |
|---|---|---|
$fields | array | Must be greater than the longest line (in characters) to be found in the CSV file (allowing for trailing line-end characters). Otherwise the line is split in chunks of length characters, unless the split would occur inside an enclosure. Omitting this parameter (or setting it to 0 in PHP 5.1.0 and later) the maximum line length is not limited, which is slightly slower. |
$delimiter | string | the optional delimiter parameter sets the field delimiter (one character only) |
$enclosure | string | the optional enclosure parameter sets the field enclosure character (one character only) |
$escape | string | the optional escape parameter sets the escape character (one character only) |
rename
Renames a file or directory.
public rename(string $newname): boolNOTE: This will not work if the file is currently opened by another process.
Parameters
| Parameter | Type | Description |
|---|---|---|
$newname | string | The new name. Must not be an absolute/relative path. If you want to move the file use File::moveTo(). |
delete
public delete(string $path): boolParameters
| Parameter | Type | Description |
|---|---|---|
$path | string |
jsonSerialize
public jsonSerialize(): mixedperms
public perms(): ?intchmod
public chmod(int $mode): boolParameters
| Parameter | Type | Description |
|---|---|---|
$mode | int |
isEncrypted
Check if a file is encrypted using the built-in Hazaar encryption method.
public isEncrypted(): boolencrypt
public encrypt(): booldecrypt
public decrypt(): boolisOpen
public isOpen(): boolopen
public open(string $mode): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$mode | string |
read
public read(int $length): stringParameters
| Parameter | Type | Description |
|---|---|---|
$length | int |
write
public write(string $bytes, int $length): intParameters
| Parameter | Type | Description |
|---|---|---|
$bytes | string | |
$length | int |
seek
public seek(int $offset, int $whence = 'SEEK_SET'): intParameters
| Parameter | Type | Description |
|---|---|---|
$offset | int | |
$whence | int |
tell
public tell(): inteof
public eof(): booltruncate
public truncate(int $size): boolParameters
| Parameter | Type | Description |
|---|---|---|
$size | int |
lock
public lock(int $operation, ?int $wouldblock): boolParameters
| Parameter | Type | Description |
|---|---|---|
$operation | int | |
$wouldblock | int |
flush
public flush(): boolgets
public gets(?int $length): stringParameters
| Parameter | Type | Description |
|---|---|---|
$length | int |
close
public close(): boolfilterIn
Internal content filter.
protected filterIn(string $content): boolChecks if the content is modified in some way using a BOM mask. Currently this is used to determine if a file is encrypted and automatically decrypts it if an encryption key is available.
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string |
filterOut
Internal content filter.
protected filterOut(string $content): boolChecks if the content is modified in some way using a BOM mask. Currently this is used to determine if a file is encrypted and automatically decrypts it if an encryption key is available.
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string |
getEncryptionKey
private getEncryptionKey(): stringGenerated by Hazaar API Doc Generator on Mon, 27 Oct 2025 13:01:29 +0000