How to Upload Image using Proffer Component in PHP?

Total Post:6


 1214  View(s)
Rate this:
Hi, I have built an application using php programming and I want to upload image using proffer component in PHP. I usually search for many php questions and answers queriesphp questions and answers queries, which fortunately get resolved in such Q&A forums. So again, I am hoping that some of the tech experts in this community can help to figure out my issue.
  1. Re: How to Upload Image using Proffer Component in PHP?

    First, you need to install Proffer Component in your project directory .Open your terminal and go to your project directory then Run below command.

                                $ composer require 'davidyell/proffer:~0.6'
    After installing Proffer Component you'll need to load the plugin in your config/bootstrap.php file.

    Ones the plugin is loaded in your bootstrap.php file now creates an upload field here we are using articles table which contains articles details with image.

    articles table          


    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,

    `title` varchar(50) DEFAULT NULL,
    `body` text,
    `image` varchar(255) NOT NULL,
    `image_dir` varchar(255) NOT NULL,
    `created` datetime DEFAULT NULL,
    `modified` datetime DEFAULT NULL,
    PRIMARY KEY (`id`)

    Now you need to ensure that the fields are present in your entities $_accessible array.            


    // Make all fields mass assignable except for primary key field "id".
    protected $_accessible = [
    '*' => true,
    'id' => false,
    Now Need to Configuring the behaviour in your Table Model.

    Configuring Input field in your templates.

    // Add the behaviour and configure any options you want
    $this->addBehavior('Proffer.Proffer', [
                    'image' => [ // The name of your upload field
                        'root' => WWW_ROOT . 'img', // Customise the root upload folder here, or omit to use the default
                        'dir' => 'image_dir', // The name of the field to store the folder
                        'thumbnailSizes' => [ // Declare your thumbnails
                            'square' => [ // Define the prefix of your thumbnail
                                'w' => 200, // Width
                                'h' => 200, // Height
                                'jpeg_quality' => 100
                            'portrait' => [ // Define a second thumbnail
                                'w' => 100,
                                'h' => 300
                        'thumbnailMethod' => 'gd' // Options are Imagick or Gd


    I hope this will help you.

    echo $this->Form->create($article,array('type' => 'file');
    echo $this->Form->input('title');
    echo $this->Form->input('body', ['rows' => '4']);
    echo $this->Form->input('image', ['type' => 'file']);
    echo $this->Form->button(__('Save Article');
    echo $this->Form->end();

      Modified On Apr-11-2018 06:29:25 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.