PHP code example of codeinc / temp-file

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

    

codeinc / temp-file example snippets



use CodeInc\TempFile\TempFile;

// you can optionally specify a prefix and the parent directory to the constructor
$tempFile = new TempFile('my_temp_file_', '/tmp'); // creates the temp file
$tempFile->getPath(); // returns the temp file's path
(string)$tempFile; // equals to getPath(), returns the temp file's path
$tempFile->getSize(); // returns the temp file's size
$tempFile->getContents(); // returns the temp file's content
$tempFile->putContents(''); // set the temp file's content 
unset($tempFile); // deletes the temp file


use CodeInc\TempFile\TempFile;

$tempFile = new TempFile(null, null, false);
$tempFilePath = $tempFile->getPath();
unset($tempFile); 

// will return TRUE, the temp file is NOT deleted by the class destructor
file_exists($tempFilePath);