class File (View source)

File wrapper class

Properties

protected string $name
protected string $content
protected Message|null $error_message
protected bool $is_temp
protected string $compression
protected int $offset
protected int $chunk_size
protected resource|null $handle
protected bool $decompress
protected string $charset

Methods

__construct(bool|string $name = false)

No description

__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|null
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

__construct(bool|string $name = false)

Parameters

bool|string $name file name or false

__destruct()

destructor

See also

bool cleanUp()

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

Return Value

bool success

bool delete()

deletes the file

Return Value

bool success

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

void setName(string|null $name)

accessor

Parameters

string|null $name file name

Return Value

void

string|false|null getRawContent()

Gets file content

Return Value

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

string|false getContent()

Gets file content

Return Value

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

bool isUploaded()

Whether file is uploaded.

Return Value

bool

string|null getName()

accessor

Return Value

string|null File::$_name

bool setUploadedFile(string $name)

Initializes object from uploaded file.

Parameters

string $name name of file uploaded

Return Value

bool success

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

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

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

Message|null getError()

Returns possible error message.

Return Value

Message|null error message

bool isError()

Checks whether there was any error.

Return Value

bool whether an error occurred or not

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

bool setLocalSelectedFile(string $name)

Sets named file to be read from UploadDir.

Parameters

string $name file name

Return Value

bool success

bool isReadable()

Checks whether file can be read.

Return Value

bool whether the file is readable or not

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

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

void setDecompressContent(bool $decompress)

Sets whether the content should be decompressed before returned

Parameters

bool $decompress whether to decompress

Return Value

void

resource getHandle()

Returns the file handle

Return Value

resource file handle

void setHandle(resource $handle)

Sets the file handle

Parameters

resource $handle file handle

Return Value

void

void errorUnsupported()

Sets error message for unsupported compression.

Return Value

void

bool open()

Attempts to open the file.

Return Value

bool

bool openZip(string|null $specific_entry = null)

Opens file from zip

Parameters

string|null $specific_entry Entry to open

Return Value

bool

bool eof()

Checks whether we've reached end of file

Return Value

bool

void close()

Closes the file

Return Value

void

string read(int $size)

Reads data from file

Parameters

int $size Number of bytes to read

Return Value

string

string getCharset()

Returns the character set of the file

Return Value

string character set of the file

void setCharset(string $charset)

Sets the character set of the file

Parameters

string $charset character set of the file

Return Value

void

string getCompression()

Returns compression used by file.

Return Value

string MIME type of compression, none for none

int getOffset()

Returns the offset

Return Value

int the offset

int getChunkSize()

Returns the chunk size

Return Value

int the chunk size

void setChunkSize(int $chunk_size)

Sets the chunk size

Parameters

int $chunk_size the chunk size

Return Value

void

int getContentLength()

Returns the length of the content in the file

Return Value

int the length of the file content