【问题标题】:CakePHP Upload Plugin - Field 'photo_dir' doesn't have a default valueCakePHP 上传插件 - 字段 'photo_dir' 没有默认值
【发布时间】:2017-04-20 22:48:09
【问题描述】:

我正在尝试在新主机中设置旧的 cakePHP 应用程序,但突然在共享的 godaddy 主机上出现此错误。它在旧主机中运行良好。我已经在 CakePHP 上工作了 2 年,但似乎不明白为什么会这样。我正在使用以下上传插件cakephp-upload

Error: SQLSTATE[HY000]: General error: 1364 Field 'photo_dir' doesn't have a default value
SQL Query: INSERT INTO `prayag_cms`.`galleries` (`branch_id`, `name`, `album_id`, `display_photo`, `modified`, `created`) VALUES (0, 'Photo', 1, 'CpLMQ28WYAEOnow.jpg_large.jpg', '2016-12-06 10:17:14', '2016-12-06 10:17:14')

这是我的确认

public $actsAs = array(
            'Containable',
    'Upload.Upload' => array(
        'display_photo' => array(
            'fields' => array(
                'dir' => 'photo_dir'
            ),
                            'thumbnailSizes' => array(
                'small' => '250x250',
            ),
                            'thumbnailMethod' => 'php',
                            'path' => '{ROOT}webroot{DS}img{DS}{model}{DS}',
        ),

    )
);

控制器:

public function admin_add() {
    if ($this->request->is('post')) {
        $this->Gallery->create();
        if ($this->Gallery->save($this->request->data)) {
            $this->Session->setFlash(__('The gallery has been saved.'), 'admin/flash_success');
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The gallery could not be saved. Please, try again.'), 'admin/flash_error');
        }
    }
    $branches = $this->Gallery->Branch->find('list');
    $albums = $this->Gallery->Album->find('list');
    $this->set(compact('branches', 'albums'));
}

【问题讨论】:

    标签: php cakephp file-upload cakephp-2.4


    【解决方案1】:

    文件夹不存在(webroot/img/users[model])或没有足够的权限创建新文件夹或访问文件夹。

    1. 因此照片未上传
    2. 如果照片未上传,则photo_dir 分配为NULL
    3. 但您的数据库字段不接受 NULL 值
    4. 然后你会得到这些错误

    希望你的问题能得到解决

    【讨论】:

    • 我已经给了777,但它仍然没有创建文件夹。有什么想法吗?
    • 可能您必须递归地授予 img 文件夹 777 的权限。您现在可以创建所需的 (webroot/img/users[model]) 文件夹并授予检查权限
    猜你喜欢
    • 2012-09-25
    • 2018-03-19
    • 2014-11-09
    • 2015-07-07
    • 2019-11-22
    • 2018-07-29
    • 2018-07-09
    • 2018-07-14
    • 2020-05-29
    相关资源
    最近更新 更多