File Handler | Summit
FileHandler helps you read,write,upload and delete files to your web application.
Configuration
Below are the configuration variables for the database.
| Option | Description |
|---|---|
| file_types | Allowed file extensions to be uploaded. * means all |
| max_size | Maximum file size allowed to be uploaded. (in MB) |
| overwrite | If set to 1 files will be overwritten. If set to 0 a number will be put in front of the file name |
Methods
Init($config)
The Init method will initialize the FileHandler class with the configuration given.
FileHandler::Init($config);
Download($filename, $content)
The Download method will force the browser to trigger the download window to download data to your desktop.
FileHandler::Download('test.txt', 'some text here');
Read($file)
The Read reads the contents of a file and returns an array with a status code (success/error) and the contents.
$read = FileHandler::Read('/path/to/file/test.txt');
if ($read['status'] == 1) {
echo $read['content'];
} else {
echo $read['message'];
}
Remove($filename)
The Download method will force the browser to trigger the download window to download data to your desktop.
$remove = FileHandler::Remove('/path/to/file/test.txt');
if ($remove['status'] != 0) {
echo $remove['message'];
} else {
echo 'success';
}
Upload($fieldname)
The Upload method assists you in uploading files to the web server. $fieldname is the name of your <input type="file" /> field on your form.
$upload = FileHandler::Upload('profilepicture');
if ($upload['status'] != 0) {
echo $upload['file_name'];
echo $upload['file_size'];
echo $upload['file_path'];
} else {
echo $upload['message'];
}
Write($file, $contents)
The Write method writes content to a file.
$write = FileHandler::Write('/path/to/file/test.txt', 'hello world');
if ($write['status'] == 1) {
echo 'success';
} else {
echo $write['message'];
}

