PHP code example of marten-cz / upload-manager

1. Go to this page and download the library: Download marten-cz/upload-manager 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/ */

    

marten-cz / upload-manager example snippets


/** @var \ondrs\UploadManager\Upload @inject
public $upload;

public function renderUpload()
{
    $this->upload->filesToDir('path/to/dir');
}

public function processForm($form)
{
    /** @var Nette\Http\FileUpload */
    $fileUpload = $form->values->file;

    $this->upload->singleFileToDir('path/to/dir', $fileUpload);
}

/**
 * @param int $eventId
 */
public function uploadAttachment($eventId)
{
    /**
     * @param FileUpload $fileUpload
     * @param \SplFileInfo $uploadedFile
     * @param $path
     */
    $this->upload->onFileComplete[] = function (\SplFileInfo $uploadedFile, FileUpload $fileUpload, $path) use ($eventId) {

        $filename = $uploadedFile->getFilename();

        $this->db->table('crm_attachments')
            ->insert([
                'filename' => $filename,
                'path' => $path,
                'crm_events_id' => $eventId,
            ]);
    };

    /**
     * @param array $files
     * @param array $uploadedFiles
     */
    $this->upload->onQueueComplete[] = function(array $files, array $uploadedFiles) use($eventId) {

        $uploadedFiles = array_map(function($i) {
            return $i->getFilename();
        }, $uploadedFiles);

        $this->db->table('crm_events')
            ->wherePrimary($eventId)
            ->update([
                'text' => implode(';', $uploadedFiles),
            ]);
    };

    $this->upload->filesToDir('attachments/' . $eventId);
}