class File

File wrapper class

Properties

protected string $_name
protected string $_content
protected Message|null $_error_message
protected bool $_is_temp
protected string $_compression
protected integer $_offset
protected integer $_chunk_size
protected resource|null $_handle
protected boolean $_decompress
protected string $_charset

Methods

__construct(boolean|string $name = false)

constructor

__destruct()

destructor

bool
cleanUp()

deletes file if it is temporary, usually from a moved upload file

bool
delete()

deletes the file

bool
isTemp(bool|null $is_temp = null)

checks or sets the temp flag for this file file objects with temp flags are deleted with object destruction

void
setName(string|null $name)

accessor

string|false
getRawContent()

Gets file content

string|false
getContent()

Gets file content

bool
isUploaded()

Whether file is uploaded.

string|null
getName()

accessor

bool
setUploadedFile(string $name)

Initializes object from uploaded file.

bool
setUploadedFromTblChangeRequest(string $key, string $rownumber)

Loads uploaded file from table change request.

array
fetchUploadedFromTblChangeRequestMultiple(array $file, string $rownumber, string $key)

strips some dimension from the multi-dimensional array from $_FILES

bool
setSelectedFromTblChangeRequest(string $key, string|null $rownumber = null)

sets the name if the file to the one selected in the tbl_change form

Message|null
getError()

Returns possible error message.

bool
isError()

Checks whether there was any error.

bool
checkTblChangeForm(string $key, string $rownumber)

checks the superglobals provided if the tbl_change form is submitted and uses the submitted/selected file

bool
setLocalSelectedFile(string $name)

Sets named file to be read from UploadDir.

bool
isReadable()

Checks whether file can be read.

bool
checkUploadedFile()

If we are on a server with open_basedir, we must move the file before opening it. The FAQ 1.11 explains how to create the "./tmp" directory - if needed

string|false
detectCompression()

Detects what compression the file uses

void
setDecompressContent(bool $decompress)

Sets whether the content should be decompressed before returned

resource
getHandle()

Returns the file handle

void
setHandle(resource $handle)

Sets the file handle

void
errorUnsupported()

Sets error message for unsupported compression.

bool
open()

Attempts to open the file.

bool
openZip(string|null $specific_entry = null)

Opens file from zip

bool
eof()

Checks whether we've reached end of file

void
close()

Closes the file

string
read(int $size)

Reads data from file

string
getCharset()

Returns the character set of the file

void
setCharset(string $charset)

Sets the character set of the file

string
getCompression()

Returns compression used by file.

int
getOffset()

Returns the offset

int
getChunkSize()

Returns the chunk size

void
setChunkSize(int $chunk_size)

Sets the chunk size

int
getContentLength()

Returns the length of the content in the file

Details

at line 93
__construct(boolean|string $name = false)

constructor

Parameters

boolean|string $name file name or false

at line 110
__destruct()

destructor

See also

at line 121
bool cleanUp()

deletes file if it is temporary, usually from a moved upload file

Return Value

bool success

at line 136
bool delete()

deletes the file

Return Value

bool success

at line 150
bool isTemp(bool|null $is_temp = null)

checks or sets the temp flag for this file file objects with temp flags are deleted with object destruction

Parameters

bool|null $is_temp sets the temp flag

Return Value

bool File::$_is_temp

at line 167
void setName(string|null $name)

accessor

Parameters

string|null $name file name

Return Value

void

at line 180
string|false getRawContent()

Gets file content

Return Value

string|false the binary file content, or false if no content

at line 211
string|false getContent()

Gets file content

Return Value

string|false the binary file content as a string, or false if no content

at line 227
bool isUploaded()

Whether file is uploaded.

Return Value

bool

at line 242
string|null getName()

accessor

Return Value

string|null File::$_name

at line 255
bool setUploadedFile(string $name)

Initializes object from uploaded file.

Parameters

string $name name of file uploaded

Return Value

bool success

at line 277
bool setUploadedFromTblChangeRequest(string $key, string $rownumber)

Loads uploaded file from table change request.

Parameters

string $key the md5 hash of the column name
string $rownumber number of row to process

Return Value

bool success

at line 361
array fetchUploadedFromTblChangeRequestMultiple(array $file, string $rownumber, string $key)

strips some dimension from the multi-dimensional array from $_FILES

$file['name']['multi_edit'][$rownumber][$key] = [value] $file['type']['multi_edit'][$rownumber][$key] = [value] $file['size']['multi_edit'][$rownumber][$key] = [value] $file['tmp_name']['multi_edit'][$rownumber][$key] = [value] $file['error']['multi_edit'][$rownumber][$key] = [value]

// becomes:

$file['name'] = [value] $file['type'] = [value] $file['size'] = [value] $file['tmp_name'] = [value] $file['error'] = [value]

Parameters

array $file the array
string $rownumber number of row to process
string $key key to process

Return Value

array

at line 386
bool setSelectedFromTblChangeRequest(string $key, string|null $rownumber = null)

sets the name if the file to the one selected in the tbl_change form

Parameters

string $key the md5 hash of the column name
string|null $rownumber number of row to process

Return Value

bool success

at line 408
Message|null getError()

Returns possible error message.

Return Value

Message|null error message

at line 419
bool isError()

Checks whether there was any error.

Return Value

bool whether an error occurred or not

at line 434
bool checkTblChangeForm(string $key, string $rownumber)

checks the superglobals provided if the tbl_change form is submitted and uses the submitted/selected file

Parameters

string $key the md5 hash of the column name
string $rownumber number of row to process

Return Value

bool success

at line 458
bool setLocalSelectedFile(string $name)

Sets named file to be read from UploadDir.

Parameters

string $name file name

Return Value

bool success

at line 487
bool isReadable()

Checks whether file can be read.

Return Value

bool whether the file is readable or not

at line 503
bool checkUploadedFile()

If we are on a server with open_basedir, we must move the file before opening it. The FAQ 1.11 explains how to create the "./tmp" directory - if needed

Return Value

bool whether uploaded file is fine or not

at line 556
protected string|false detectCompression()

Detects what compression the file uses

Return Value

string|false false on error, otherwise string MIME type of compression, none for none

at line 580
void setDecompressContent(bool $decompress)

Sets whether the content should be decompressed before returned

Parameters

bool $decompress whether to decompress

Return Value

void

at line 590
resource getHandle()

Returns the file handle

Return Value

resource file handle

at line 605
void setHandle(resource $handle)

Sets the file handle

Parameters

resource $handle file handle

Return Value

void

at line 616
void errorUnsupported()

Sets error message for unsupported compression.

Return Value

void

at line 633
bool open()

Attempts to open the file.

Return Value

bool

at line 683
bool openZip(string|null $specific_entry = null)

Opens file from zip

Parameters

string|null $specific_entry Entry to open

Return Value

bool

at line 700
bool eof()

Checks whether we've reached end of file

Return Value

bool

at line 713
void close()

Closes the file

Return Value

void

at line 732
string read(int $size)

Reads data from file

Parameters

int $size Number of bytes to read

Return Value

string

at line 754
string getCharset()

Returns the character set of the file

Return Value

string character set of the file

at line 766
void setCharset(string $charset)

Sets the character set of the file

Parameters

string $charset character set of the file

Return Value

void

at line 777
string getCompression()

Returns compression used by file.

Return Value

string MIME type of compression, none for none

at line 791
int getOffset()

Returns the offset

Return Value

int the offset

at line 801
int getChunkSize()

Returns the chunk size

Return Value

int the chunk size

at line 813
void setChunkSize(int $chunk_size)

Sets the chunk size

Parameters

int $chunk_size the chunk size

Return Value

void

at line 823
int getContentLength()

Returns the length of the content in the file

Return Value

int the length of the file content