PHP code example of iphp / filestore-bundle

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

    

iphp / filestore-bundle example snippets

 php
// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
         new Iphp\FileStoreBundle\IphpFileStoreBundle(),
    );
)
 php


namespace Iphpsandbox\PhotoBundle\Entity;
use Iphp\FileStoreBundle\Mapping\Annotation as FileStore;
use Symfony\Component\Validator\Constraints as Assert;
 
/**
 * @FileStore\Uploadable
 */
class Photo
{
    /**
     * @var int
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
    
   /**
     * @var array
     * @ORM\Column(type="array", nullable=true)
     */
    private $photoInfo;

    /**
     * @var File
     * @Assert\File( maxSize="20M")
     * @FileStore\UploadableField(mapping="photo", fileDataProperty ="photoInfo")
     */
    private $photoUpload;

    ...
     /* Getters and setters */
    ...
}
 php


namespace Iphpsandbox\PhotoBundle\Entity;
use Iphp\FileStoreBundle\Mapping\Annotation as FileStore;
use Symfony\Component\Validator\Constraints as Assert;
 
/**
 * @FileStore\Uploadable
 */
class Photo
{
    /**
     * @var int
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
    
    /**
     * @var File
     * @Assert\File( maxSize="20M")
     * @FileStore\UploadableField(mapping="photo")
     * @ORM\Column(type="array", nullable=true)
     */
    private $photo;

    ...
     /* Getters and setters */
    ...
}
 php
$photo = ... // load entity from db
$path = $photo->getPhoto()['path'];
 php


namespace Iphpsandbox\PhotoBundle\Admin;
 
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Iphp\FileStoreBundle\Form\Type\FileType as IphpFileType;
 
class PhotoAdmin extends Admin
{
    protected function configureListFields(ListMapper $listMapper)
    {
        return $listMapper->addIdentifier('title')
                          ->add ('date');
    }
 
    protected function configureFormFields(FormMapper $formMapper)
    {
        return $formMapper->add('title')
                         ->add ('date')
                         ->add('photo', IphpFileType::class);
    }
}