douhu4091 2014-02-18 01:55
浏览 38
已采纳

Cakephp SQL错误1054字段列表上传图像文件中的未知列

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?

  • 写回答

1条回答 默认 最新

  • dongnuo6310 2014-02-18 02:19
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码