1. Go to this page and download the library: Download webfiori/file library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webfiori / file example snippets
php
$file = new File('path/to/my/file.txt');
$file->read();
$fileData = $file->getRawData();
// Do anything you like with data string.
php
$file = new File('path/to/my/new/file.txt');
//The method File::create() is used to create new files
$file->create();
$file->setRawData('Hello World');
$file->write();
php
$file = new File('path/to/my/old/file.txt');
$file->setRawData('Hello');
$file->write();
$file->setRawData(' World');
$file->write();
//Setting raw data before each call to the method File::write() will append to file.
php
$file = new File('path/to/my/old/file.txt');
$file->setRawData('Hello');
$file->write();
$file->setRawData(' World');
$file->write(true);
//By supplying true as parameter to the method File::write(), the old content of the file will be overridden.
php
$file = new File('file.txt');
//'Hello World!' in base64
$encodedData = 'SGVsbG8gV29ybGQh';
$file->setRawData($encodedData, true);
$decoded = $file->getRawData();
//$decoded is now the string 'Hello World!'
//By supplying true as second parameter to the method File::setRawData(), the method will decode given data
php
$file = new File('file.txt');
$file->setRawData('Hello World');
$encoded = $file->getRawData(true);
//$encoded is now the string 'SGVsbG8gV29ybGQh'
//By supplying true as second parameter to the method File::getRawData(), the method will encode given data
php
$file = new File('some-binary-with-encoded.bin');
$file->readDecoded();
$decoded = $file->getRawData();
php
$file = new File('some-pdf.pdf');
$file->read();
$file->view();
php
$file = new File('some-pdf.pdf');
$file->read();
$file->view(true);
php
$file = new File('some-big-movie-file.mp4');
$file->read();
//The size of each chunk will be 1500 bytes and they will be base 64 encoded by default.
$dataChunks = $file->getChunks(1500);
foreach ($dataChunks as $chunk) {
//......
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.