PHP code example of devnullius / php-tmp-file

1. Go to this page and download the library: Download devnullius/php-tmp-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/ */

    

devnullius / php-tmp-file example snippets



use devnullius\tmp\File;

$file = new File('some content', '.html');

// send to client for download
$file->send('home.html');

// save to disk
$file->saveAs('/dir/test.html');

// Access file name and directory
echo $file->getFileName();
echo $file->getTempDir();


use devnullius\tmp\File;

$file = new File('some content', '.html');
$file->delete = false;


use devnullius\tmp\File;

$file = new File('some content', '.html');

$file->setResponseMethod(static function ($_filename, $filename) {
    \Yii::$app->response->sendFile($_filename, $filename);
});
$fileName = 'greatFileName.txt';
// and if there is set any response method it's going to be executed
$file->send($fileName);