Cakephp上载插件不保存图像
我正在尝试上传图片并使用cakephp上传插件2.0(最新版本)保存它们。这是我的数据库表:Cakephp上载插件不保存图像,php,cakephp,upload,Php,Cakephp,Upload,我正在尝试上传图片并使用cakephp上传插件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 DEFAU
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)
最后,这是我的观点
<?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')); ?>
我已经阅读了给定的图片,但仍然没有保存到webroot/files/。。。
我在Windows7中使用CakePHP2.4.7和PHP5.4。我没有安装Imagick,因为WAMP 2.2启用了GD2
我还应该做些什么才能使这项工作起作用?更新评论以正式回答这个问题--- 改变
echo$this->Form->create('Photo')代码>到echo$this->Form->create('Photo',array('type'=>'file')代码>
及
echo$this->Form->input('imgpath')
toecho$this->Form->input('imgpath',array('type'=>'hidden')代码>在表单创建时添加类型<代码>$this->Form->create('Photo',array('type'=>'file')代码>和echo$this->Form->input('imgpath',array('type'=>'hidden')@Fazallasel非常感谢您现在图像保存在文件夹中,但为什么我的数据库imgpath无法获取图像保存的路径???如果你能把上面的评论作为答案,我会接受它作为正确答案你知道为什么imgpath没有被保存吗?你能提供我更多的细节吗。。。请将debug($this->data)
放在Photo.php
modelsbeforeSave()
上,并告诉我详细信息……它似乎是空的。但除了imgpath之外,其他信息都会被保存!我知道它是空的,但我想看看图案。。好的,尝试在字段名之前添加模型名,就像文档建议的那样,比如echo$this->Form->input('Photo.imgpath',array('type'=>'hidden')代码>我的意思是,即使看到一个图案,它也不会打印任何东西:(我按照建议做了,但仍然不起作用。我在模型中放置它的方式正确吗?'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')); ?>