title: Uploading image in cakephp and storing it's path in database
body: <p>I have a form in which i am trying to upload image and trying to store that in database.
  My Controller Code is:</p>
  
  <pre><code>class OlxProductsController extends AppController{
  public function post(){
      if($this-&gt;request-&gt;is('post')) {
              if ($this-&gt;request-&gt;data['OlxProduct']['img_upload']) {
                  $file = $this-&gt;data['OlxProduct']['img_upload']; //put the data into a var for easy use
                  //   print_r($file);
                  $filename = str_replace(" ", "-", rand(1, 3000) . $file['name']);
                  move_uploaded_file($file['tmp_name'], WWW_ROOT . 'img/uploads/' . $filename);
                  //echo $filename; die();
                  $this-&gt;request-&gt;data['OlxProduct']['img_upload'] = $filename;
              } else {
                  unset($this-&gt;request-&gt;data['OlxProduct']['img_upload']);
              }
  
              $this-&gt;OlxProduct-&gt;save($this-&gt;request-&gt;data);
              $this-&gt;Session-&gt;setFlash('posted successfully');
              $this-&gt;redirect(array('controller' =&gt; 'OlxUsers', 'action' =&gt; 'account'));
      }
      else {
              $this-&gt;Session-&gt;setFlash('ad has not been saved');
      }
    }
  }
  </code></pre>
  
  <p>post action code is:
  //post.ctp</p>
  
  <pre><code>&lt;form action="../post"   method="post" enctype="multipart/form-data" &gt;
  &lt;?php
  echo $this-&gt;Form-&gt;input('ad_title');
  echo $this-&gt;Form-&gt;input('category');
  echo $this-&gt;Form-&gt;input('price',array('type'=&gt;'number'));
  echo $this-&gt;Form-&gt;input('ad_description',array('type'=&gt;'textarea',));
  echo $this-&gt;Form&gt;input('img_upload',array('class'=&gt;'txtbox','type'=&gt;'file'));
  echo $this-&gt;Form-&gt;end('Post Ad');
  ?&gt;
  </code></pre>
  
  <p>But I on executing above code, I am getting this error:</p>
  
  <blockquote>
    <p>Notice (8): Undefined index: OlxProduct<br>
    [APP\Controller\OlxProductsController.php, line 17] Notice (8): Array
    to string conversion [CORE\Cake\Model\Datasource\DboSource.php, line
    1009] Database Error Error: SQLSTATE[42S22]: Column not found: 1054
    Unknown column 'Array' in 'field list'</p>
  </blockquote>