PHPackages                             iphp/filestore-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. iphp/filestore-bundle

ActiveBundle[File &amp; Storage](/categories/file-storage)

iphp/filestore-bundle
=====================

Upload files for doctrine entities in symfony 2 project

v0.3.1(9y ago)50143.2k↓42.9%25[15 issues](https://github.com/vitiko/IphpFileStoreBundle/issues)[2 PRs](https://github.com/vitiko/IphpFileStoreBundle/pulls)2MITPHPPHP ^5.5 || ^7.0

Since Mar 21Pushed 9y ago7 watchersCompare

[ Source](https://github.com/vitiko/IphpFileStoreBundle)[ Packagist](https://packagist.org/packages/iphp/filestore-bundle)[ Docs](http://symfonydev.ru)[ RSS](/packages/iphp-filestore-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (15)Versions (11)Used By (2)

IphpFileStoreBundle - Symfony 2 Doctrine ORM file upload bundle
===============================================================

[](#iphpfilestorebundle---symfony-2-doctrine-orm-file-upload-bundle)

[![Build Status](https://camo.githubusercontent.com/9be9bd5b5820c9318666ac3665619a911a78fcc8a34b90e217260a328a7fad0c/68747470733a2f2f6170692e7472617669732d63692e6f72672f766974696b6f2f4970687046696c6553746f726542756e646c652e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/vitiko/IphpFileStoreBundle)[![Total Downloads](https://camo.githubusercontent.com/4443c5a81c3cce6fce49e6f6c6c9a5fc2720a5957cd8c2889718742e90e6c882/68747470733a2f2f706f7365722e707567782e6f72672f697068702f66696c6573746f72652d62756e646c652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/iphp/filestore-bundle)[![Code Climate](https://camo.githubusercontent.com/2cbcbda1066d727e104e0aae7594dad1553774abfe3167644a0449d1ad2845de/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f766974696b6f2f4970687046696c6553746f726542756e646c652f6261646765732f6770612e737667)](https://codeclimate.com/github/vitiko/IphpFileStoreBundle)

The IphpFileStoreBundle is a Symfony2 bundle that automates file uploads that are attached to an entity. The bundle will automatically name and save the uploaded file according to the configuration specified on a per property basis using a mix of configuration and annotations. After the entity has been created and the file has been saved, array with data of uploaded file will be saved to according property. The bundle provide different ways to naming uploaded files and directories.

For Russian documentation see

Installation
------------

[](#installation)

### Get the bundle

[](#get-the-bundle)

Add the following lines in your composer.json:

```
{
    "require": {
        "iphp/filestore-bundle" : "@stable"
    }
}

```

### Initialize the bundle

[](#initialize-the-bundle)

To start using the bundle, register the bundle in your application's kernel class:

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

Usage
-----

[](#usage)

IphpFileStoreBundle try to handle file uploads according to a combination of configuration parameters and annotations. In order to have your upload working you have to:

- Define a basic configuration set
- Annotate your Entities

### Configuration

[](#configuration)

```
# app/config/config.yml
iphp_file_store:
    mappings:
       photo:
           upload_dir:  %kernel.root_dir%/../web/photo
           upload_path: /photo
```

The `upload_dir` and `upload_path` is the only required configuration options for an entity mapping.

All options are listed below:

- `upload_dir`: directory to upload the file to
- `upload_path`: web path of upload dir
- `namer`: configuration of file naming (See [Namers](#namers) section below)
- `directory_namer`: configuration of directory naming
- `delete_on_remove`: Set to true if the file should be deleted from the filesystem when the entity is removed
- `overwrite_duplicates`: Set to true if the file with same name will be overwritten by a new file. In another case (by default), to the name of the new file will be added extra digits

### Annotate Entities

[](#annotate-entities)

In order for your entity to work with the bundle, you need to add a few annotations to it. First, annotate your class with the `Uploadable` annotation. This lets the bundle know that it should look for files to upload in your class when it is saved, inject the files when it is loaded and check to see if it needs to remove files when it is removed. Next, you should annotate the fields which hold the instance of `Symfony\Component\HttpFoundation\File\UploadedFile` when the form is submitted with the `UploadableField` annotation. The `UploadableField` annotation has a few required options. They are as follows:

- `mapping`: The mapping specified in the bundle configuration to use
- `fileDataProperty`: name of field, where are stored file data

Lets look at an example using a fictional `Photo` ORM entity:

#### recommended use case - upload in one field (uploadPhoto), store file data in another field (photo)

[](#recommended-use-case---upload-in-one-field-uploadphoto-store-file-data-in-another-field-photo)

```
