【问题标题】:Cakephp-upload plugin not saving imagesCakephp-upload 插件不保存图像
【发布时间】:2014-06-07 03:33:30
【问题描述】:

我正在尝试使用 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;

这是模型文件。 (照片.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。

我还应该做些什么来完成这项工作?

【问题讨论】:

  • 在创建表单时添加类型。 $this-&gt;Form-&gt;create('Photo', array('type' =&gt; 'file')); 和 echo $this->Form->input('imgpath', array('type' => 'hidden'));
  • @FazalRasel 非常感谢,现在图像已保存在文件夹中,但为什么我的数据库 imgpath 没有获得图像保存的路径???如果您可以将上述评论作为答案,我将接受它作为正确答案。 :)

标签: php cakephp upload


【解决方案1】:

更新 cmets 以正式给出这个答案---

改变 echo $this-&gt;Form-&gt;create('Photo');echo $this-&gt;Form-&gt;create('Photo', array('type' =&gt; 'file'));

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

【讨论】:

  • 你知道为什么 imgpath 没有被保存吗?
  • 能否请您提供更多详细信息... 将debug($this-&gt;data) 放在Photo.php 模型beforeSave() 上,让我知道详细信息...
  • 好像是空的。但除了 imgpath 其他信息被保存!
  • 我知道它是空的,但我想看看这个模式。好吧,尝试在字段名称之前添加模型名称作为文档建议,如 echo $this-&gt;Form-&gt;input('Photo.imgpath', array('type' =&gt; 'hidden'));
  • 我的意思是即使看到一个模式它也不会打印任何东西:(我按照建议做了,但它仍然不起作用。我把它放在模型中的方式是否正确?'dir' =&gt; 'imgpath'
猜你喜欢
  • 1970-01-01
  • 2019-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多