Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cakephp上载插件不保存图像_Php_Cakephp_Upload - Fatal编程技术网

Cakephp上载插件不保存图像

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

我正在尝试上传图片并使用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 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')
to
echo$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
models
beforeSave()
上,并告诉我详细信息……它似乎是空的。但除了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')); ?>