Com\Tecnick\File\File
Function to read byte-level data
Tags
Table of Contents
- fileGetContents() : string
- Reads entire file into a string.
- fopenLocal() : resource
- Wrapper to use fopen only with local files
- fReadInt() : int
- Read a 4-byte (32 bit) integer from file.
- getAltFilePaths() : array<string|int, mixed>
- Returns an array of possible alternative file paths or URLs
- getFileData() : string
- Reads entire file into a string.
- getUrlData() : string
- Reads entire remote file into a string using CURL
- rfRead() : string
- Binary-safe file read.
- getAltLocalUrlPath() : string
- Replace URL relative path with full real server path
- getAltMissingUrlProtocol() : string
- Add missing local URL protocol
- getAltPathFromUrl() : string
- Add missing local URL protocol
- getAltUrlFromPath() : string
- Get an alternate URL from a file path
- getDefaultUrlProtocol() : string
- Get the default URL protocol (http or https)
Methods
fileGetContents()
Reads entire file into a string.
public fileGetContents(string $file)
: string
The file can be also an URL.
Parameters
- $file : string
-
Name of the file or URL to read.
Return values
string —File content
fopenLocal()
Wrapper to use fopen only with local files
public fopenLocal(string $filename,
string $mode)
: resource
Parameters
- $filename : string
-
Name of the file to open
- $mode : string
-
The fopen mode parameter specifies the type of access you require to the stream
Tags
Return values
resource —Returns a file pointer resource on success
fReadInt()
Read a 4-byte (32 bit) integer from file.
public fReadInt(resource $handle)
: int
Parameters
- $handle : resource
-
A file system pointer resource that is typically created using fopen().
Return values
int —4-byte integer
getAltFilePaths()
Returns an array of possible alternative file paths or URLs
public getAltFilePaths(string $file)
: array<string|int,
mixed>
Parameters
- $file : string
-
Name of the file or URL to read.
Return values
array<string|int, mixed> —getFileData()
Reads entire file into a string.
public getFileData(string $file)
: string
The file can be also an URL if the URL wrappers are enabled.
Parameters
- $file : string
-
Name of the file or URL to read.
Return values
string —File content or FALSE in case the file is unreadable
getUrlData()
Reads entire remote file into a string using CURL
public getUrlData(string $url)
: string
Parameters
- $url : string
-
URL to read.
Return values
string —File content or FALSE in case the file is unreadable or curl is not available
rfRead()
Binary-safe file read.
public rfRead(resource $handle,
int $length)
: string
Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached.
Parameters
- $handle : resource
-
A file system pointer resource that is typically created using fopen().
- $length : int
-
Number of bytes to read.
Tags
Return values
string —getAltLocalUrlPath()
Replace URL relative path with full real server path
protected getAltLocalUrlPath(string $file)
: string
Parameters
- $file : string
-
Relative URL path
Return values
string —getAltMissingUrlProtocol()
Add missing local URL protocol
protected getAltMissingUrlProtocol(string $file)
: string
Parameters
- $file : string
-
Relative URL path
Return values
string —local path or original $file
getAltPathFromUrl()
Add missing local URL protocol
protected getAltPathFromUrl(string $url)
: string
Parameters
- $url : string
-
Relative URL path
Return values
string —local path or original $file
getAltUrlFromPath()
Get an alternate URL from a file path
protected getAltUrlFromPath(string $file)
: string
Parameters
- $file : string
-
File name and path
Return values
string —getDefaultUrlProtocol()
Get the default URL protocol (http or https)
protected getDefaultUrlProtocol()
: string