【发布时间】: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->Form->create('Photo', array('type' => 'file'));和 echo $this->Form->input('imgpath', array('type' => 'hidden')); -
@FazalRasel 非常感谢,现在图像已保存在文件夹中,但为什么我的数据库 imgpath 没有获得图像保存的路径???如果您可以将上述评论作为答案,我将接受它作为正确答案。 :)