class File (View source)

File wrapper class

when uploading a file into a blob field, should we also consider using chunks like in import? UPDATE `table` SET `field` = `field` + [chunk]

Properties

protected string|null $name
protected string|null $content
protected Message|null $errorMessage
protected bool $isTemp
protected string|null $compression
protected int $offset
protected int $chunkSize
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 $isTemp = 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|null
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 $specificEntry = 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 $chunkSize)

Sets the chunk size

int
getContentLength()

Returns the length of the content in the file

Details

__construct(bool|string $name = false)

No description

Parameters

bool|string $name

file name or false

__destruct()

destructor

See also

File::cleanUp

bool cleanUp()

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

Return Value

bool

bool delete()

deletes the file

Return Value

bool

bool isTemp(bool|null $isTemp = null)

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

Parameters

bool|null $isTemp

sets the temp flag

Return Value

bool

void setName(string|null $name)

accessor

Parameters

string|null $name

file name

Return Value

void

string|false getRawContent()

Gets file content

Return Value

string|false

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

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

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

Message|null getError()

Returns possible error message.

Return Value

Message|null

error message

bool isError()

Checks whether there was any error.

Return Value

bool

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

bool setLocalSelectedFile(string $name)

Sets named file to be read from UploadDir.

Parameters

string $name

file name

Return Value

bool

bool isReadable()

Checks whether file can be read.

Return Value

bool

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

move check of $cfg['TempDir'] into Config?

Return Value

bool

protected string|false detectCompression()

Detects what compression the file uses

move file read part into readChunk() or getChunk() add support for compression plugins

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|null getHandle()

Returns the file handle

Return Value

resource|null

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 $specificEntry = null)

Opens file from zip

Parameters

string|null $specificEntry

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 $chunkSize)

Sets the chunk size

Parameters

int $chunkSize

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