简体   繁体   中英

Cakephp SQL Error 1054 Unknown Column In The Field List uploading image file

I'm completely confused on this. I'm trying to upload an image but I keep getting this error, I've searched the site and I've found tons of the same question but I couldn't get any of those solutions to work for me.

I have this code in my model that is supposed to convert the image array to a string.

     public function processImageUpload($check = array()) {
          if (!is_uploaded_file($check['image']['tmp_name'])){
         return FALSE;
         }
         if (!move_uploaded_file($check['image']['tmp_name'], WWW_ROOT .
             'img' . DS . 'uploads' . DS . $check['image']['name'])){
          return FALSE;
          }
             $this->data[$this->alias]['image'] = 'uploads' . DS . 
              $check['image']['name'];
          return TRUE;
     }

Next up I have my add function from PostsController

       public function add() {

        if($this->request->is('post')) {
          $this->request->data['Post']['username']= $this->Auth->user('username');
          $this->Post->create();
          $data = $this->request->data['Post'];
        if (!$data['image']['name']){
          unset($data['image']);
          }
        if($this->Post->save($data)) {
          $this->Session->setFlash(__('Your post has been saved.'));
            return $this->redirect(array('action'=>'index'));
            }
          $this->Session->setFlash(__('Unable to add your post.'));
             }
     }

Then I have my form where the file is uploaded.

echo $this->Form->create('Post', array('type' => 'file'));
echo $this->Form->input('title');
echo $this->Form->input('movie');
echo $this->Form->input('category');
echo $this->Form->input('description' , array('rows'=>'2'));
echo $this->Form->input('image', array('type' => 'file'));
echo $this->Form->end('Submit Article for Review');

So why is the function in my model not converting the array into a string? What am I not understanding here?

Because it was not supposed to.

What the function move_uploaded_file is doing is uploading your file to the server and setting the database value as its PATH , not converting to a binary file in your database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM