salamek/nette-files

File storage for Nette Framework

2.1.5 2024-03-17 20:25 UTC

This package is auto-updated.

Last update: 2024-11-17 22:01:19 UTC


README

This is a file storage for Nette Framework

Nette Files implements virtual directory structure (IStructure, IStructureRepositry) all files are stored in dataDir as their md5sum.ext, file info is implemented in IStructureFile, IStructureFileRepository and position of file in structure is implemented in IFile and IFileRepository

Instalation

The best way to install salamek/nette-files is using Composer:

$ composer require salamek/nette-files

Then you have to register extension in config.neon.

    extensions:
        files: Salamek\Files\DI\FilesExtension

    files:
        dataDir: %wwwDir%/data
        webTempDir: %wwwDir%/webtemp
        webTempPath: 'webtemp'
        iconDir: %wwwDir%/assets/file

You will need to implement:

  • IFile entity representing single file
  • IFileRepository repository for IFile
  • IStructure entity representing single structure item (Folder/Directory)
  • IStructureRepository repository for IStructure
  • IStructureFile entity representing connection of IFile to IStructure (in what folder is what file)
  • IStructureFileRepository repository for IStructureFile

Package contains trait, which you will have to use in class, where you want to use file storage. This works only for PHP 5.4+, for older version you can simply copy trait content and paste it into class where you want to use it.

<?php

class BasePresenter extends Nette\Application\UI\Presenter {

    use Salamek\Files\TImagePipe;

}

Usage

Saving files

/** @var Salamek\Files\FileStorage $fileStorage */
/** @var \SplFileInfo|FileUpload $fileUpload */
$fileStorage->processFile($fileUpload); // Saves file to `dataDir` as %wwwDir%/data/md5sum_of_file.ext

Using ImagePipe in Latte

<a href="{img IFile|IStructureFile}"><img n:img="IFile|IStructureFile, 200x200, fill"></a>

output:

<a href="%wwwDir%/data/md5sum_of_file.ext"><img src="%wwwDir%/data/200x200_fill_md5sum_of_file.ext"></a>

Resizing ImagePipe flags

For resizing (third argument) you can use these keywords - fit, fill, exact, stretch, shrink_only, stretch, fit_exact, crop. For details see comments above these constants