Reputation: 584
I am trying to upload images and save them using cakephp-upload plugin 2.0 (latest version to date). This is my database table :
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;
And here's the model file. (Photo.php)
public $actsAs = array(
'Upload.Upload' => array(
'image' => array(
'fields' => array(
'dir' => 'imgpath'
)
)
)
);
Finally, this is my view.
<?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')); ?>
I have read given instructions but still images do not save to webroot/files/... I am using cakephp 2.4.7 and php 5.4 in windows 7. I have not installed Imagick since WAMP 2.2 has GD2 enabled.
What more should I do to make this work?
Upvotes: 0
Views: 667
Reputation: 4526
Updating comments to make this answer officially---
Change
echo $this->Form->create('Photo');
to echo $this->Form->create('Photo', array('type' => 'file'));
And
echo $this->Form->input('imgpath');
to echo $this->Form->input('imgpath', array('type' => 'hidden'));
Upvotes: 0