PHP code example of kodus / tempkit

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

    

kodus / tempkit example snippets


$service = new TempFileService(__DIR__ . '/temp');

$uuids = [];

foreach ($request->getUploadedFiles() as $file) {
    $uuids[] = $service->collect($file);
}

echo json_encode($uuids);

foreach ($uuids as $uuid) {
    $file = $service->recover($uuid);

    // get information about recovered file:

    $filename = $file->getClientFilename();
    $media_type = $file->getClientMediaType();

    // move recovered file into permanent storage:

    $file->moveTo(__DIR__ . '/files/' . $file->getClientFilename());
}

$file = $service->recover($uuid);

$stream = fopen($file->getTempPath(), "r");

$filesystem->writeStream("uploads/" . $file->getClientFilename(), $stream);

fclose($stream);

$file->flush(); // optionally flush the temporary file after copying