PHP code example of salamek / nette-tempnam

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

    

salamek / nette-tempnam example snippets



/** @var Salamek\Tempnam\Tempnam @inject */
public $tempnam;

$key = 'my_tempnam_key_1'; // Lets say ID of record in database
$data = 'My File COntent'; // Lets say record from database we want as file
$updatedAt = new \DateTime('YYYY-mm-dd'); // Lets say updatedAt column from database to expire tempnam file when record in database is changed

// Load temFile Path or null
$tempFile = $this->tempnam->load($key, $updatedAt);


if ($tempFile === null)
{
    $tempFile = $this->tempnam->save($key, $data, $updatedAt);
}

echo file_get_contents($tempFile); // My File COntent

 
$this->tempnam->getTempDir(); //Returns tempDir
$this->tempnam->remove($key); //Removes tempnam file by its $key
$this->tempnam->load($key, \DateTimeInterface $updatedAt = null); //Returns tempnam file path by its key if updatedAt matches or returns null
$this->tempnam->save($key, $data, \DateTimeInterface $updatedAt = null) //Saves tempnam file by $key with $data content, returns tempnam path