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.

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

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序