PHP code example of fusic / filebinder

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

    

fusic / filebinder example snippets


        CakePlugin::load('Filebinder');

## Filebinder outline image

Filebinder manage 'virtual table' and entity.

### 'Simple attachment' model image

![Image](https://raw.github.com/fusic/filebinder/2.0/Document/filebinder_image.png)

### 'Multi fields' model image

![Image](https://raw.github.com/fusic/filebinder/2.0/Document/filebinder_multi_fields.png)

### 'Multi models' model image

![Image](https://raw.github.com/fusic/filebinder/2.0/Document/filebinder_multi_models.png)

### Entity file path image

![Image](https://raw.github.com/fusic/filebinder/2.0/Document/filebinder_filepath.png)

## Usage

Example of how to add image file with confirm page.

    
    class Post extends AppModel {
       public $name = 'Post';
       public $actsAs = array('Filebinder.Bindable');
       public $displayField = 'title';
          
       public $bindFields = array(array('field' => 'image',
                                     'tmpPath' => '/var/www/html/myapp/app/webroot/files/cache/',
                                     'filePath' => '/var/www/html/myapp/app/webroot/files/',
                                     ));
          
       public $validate = array('title' => array('notempty'),
                             'image' => array('allowExtention' => array('rule' => array('checkExtension', array('jpg')),
                                                                       'allowEmpty' => true),
                                              'illegalCode' => array('rule' => array('funcCheckFile', 'checkIllegalCode'),
                                                                    'allowEmpty' => true))
                             );
    
       /**
        * checkIllegalCode
        * check /
        public function add_success(){
            $this->Transition->checkPrev(array('add',
                                               'add_confirm'));
            $mergedData = $this->Transition->mergedData();
     
            if ($this->Post->save($mergedData)) {
                $this->Transition->clearData();
                $this->Session->setFlash(sprintf(__('The %s has been saved', true), 'post'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(sprintf(__('The %s could not be saved. Please, try again.', true), 'post'));
                $this->redirect(array('action' => 'add'));
            }
        }
    }

 add.ctp

    <div class="posts form">
      <h2> printf(__('Add %s', true), __('Post', true)); 
 echo $this->Form->create('Post', array('action' => 'add', 'type' => 'file'));
 echo $this->Form->input('title', array('type' => 'text'));
 echo $this->Form->input('body');
 echo $this->Form->input('image', array('type' => 'file'));
 echo $this->Form->submit(__('Submit', true));
 echo $this->Form->end();
 printf(__('Confirm %s', true), __('Post', true)); 
 echo h($mergedData['Post']['title']);
 echo h($mergedData['Post']['body']);
 echo $this->Label->image($mergedData['Post']['image']);
 echo $this->Form->create('Post', array('action' => 'add_confirm'));
 echo $this->Form->input('dummy', array('type' => 'hidden'));
 echo $this->Form->submit(__('Submit', true));
 echo $this->Form->end();