---
title: "How to Upload Image using Proffer Component in PHP?"  
description: "How to Upload Image using Proffer Component in PHP?"  
author: "Kyle Flores"  
published: 2017-01-30  
updated: 2017-02-20  
canonical: https://www.mindstick.com/forum/34253/how-to-upload-image-using-proffer-component-in-php  
category: "php"  
tags: ["php"]  
reading_time: 2 minutes  

---

# How to Upload Image using Proffer Component in PHP?

Hi, I have built an [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) using php [programming](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming) and I want to [upload image](https://www.mindstick.com/forum/95341/how-can-use-upload-image-control-in-asp-dot-net) using proffer [component](https://www.mindstick.com/articles/12262/learn-how-to-make-a-component-in-magento-2) in PHP. I usually [search](https://www.mindstick.com/articles/65368/best-smo-services-company-in-hyderabad-improve-search-rankings) for many php questions and answers queriesphp questions and answers queries, which fortunately get resolved in such Q&[amp](https://www.mindstick.com/forum/156207/what-is-amp);A forums. So again, I am hoping that some of the [tech](https://www.mindstick.com/services/technologies) experts in this [community](https://yourviews.mindstick.com/view/87457/khalistan-community-a-threat-to-india) can help to [figure](https://yourviews.mindstick.com/view/87536/what-are-ghosts-jobs-and-how-to-figure-out-them) out my issue.

## Replies

### Reply by Friend HRM

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.\
Plugin::load('Proffer');

\

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

```
CREATE TABLE IF NOT EXISTS `articles` (  `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.

``

src/Model/Entity/Article.php

```
// Make all fields mass assignable except for primary key field "id".    protected $_accessible = ['*' => true,'id' => false,'image'=>true,'image_dir'=>true,];
```

Now Need to Configuring the behaviour in your Table Model.

Configuring Input field in your templates.

```
<?php// 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();
```


---

Original Source: https://www.mindstick.com/forum/34253/how-to-upload-image-using-proffer-component-in-php

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
