Cakephp上传插件不保存图像

时间:2014-04-22 16:22:19

标签: php cakephp upload

我正在尝试使用cakephp-upload插件2.0(迄今为止的最新版本)上传图像并保存它们。这是我的数据库表:

CREATE TABLE IF NOT EXISTS 'photos' (
  'id' int(11) NOT NULL AUTO_INCREMENT,
  'image' varchar(100) NOT NULL,
  'imgpath' varchar(100) NOT NULL,
  'album_id' int(11) NOT NULL,
  'created' datetime DEFAULT NULL,
  'modified' datetime DEFAULT NULL,
  PRIMARY KEY ('id'),
  KEY 'idx_album_id' ('album_id')
) ENGINE=InnoDB;

这是模型文件。 (Photo.php)

 public $actsAs = array(
        'Upload.Upload' => array(
            'image' => array(
                'fields' => array(
                    'dir' => 'imgpath'
                )
            )
        )
    );

最后,这是我的观点。

<?php echo $this->Form->create('Photo'); ?>
    <fieldset>
        <legend><?php echo __('Add Photo'); ?></legend>
    <?php
        echo $this->Form->input('image', array('type' => 'file'));
        echo $this->Form->input('imgpath');
        echo $this->Form->input('album_id');
    ?>
    </fieldset>
<?php echo $this->Form->end(__('Submit')); ?>

我已阅读instructions,但静止图片无法保存到webroot / files / ... 我在Windows 7中使用cakephp 2.4.7和php 5.4。我没有安装Imagick,因为WAMP 2.2启用了GD2。

我还应该做些什么呢?

1 个答案:

答案 0 :(得分:0)

更新评论以正式回答这个问题---

更改 echo $this->Form->create('Photo');echo $this->Form->create('Photo', array('type' => 'file'));

echo $this->Form->input('imgpath');echo $this->Form->input('imgpath', array('type' => 'hidden'));

相关问题