Hey,
Luckly I saw this post at the time I was refactoring my image upload
facility, but at the moment I can't get it to work, it keeps failing
on saving the image. Here is how I have it set up:
Model:
class Image extends AppModel
{
var $name = 'Image';
var $actsAs = array('upload' => array(
'image' => array(
'dir' => 'files/Image',
'overwrite_existing' => true,
'create_directory' => true,
'allowed_mime' =>
array('image/jpeg', 'image/gif', 'image/png'),
'allowed_ext' => array('.jpg',
'.jpeg', '.png', '.gif'))
)
);
var $belongsTo = array(
'Copyright' => array( 'classname' => 'Copyright'),
'Subject' => array( 'classname' =>
'Subject'),
'User' => array( 'classname' => 'User')
);
var $hasAndBelongsToMany = array('Tag' =>
array('className' => 'Tag',
'joinTable' => 'images_tags',
'foreignKey' => 'image_id',
'associationForeignKey'=> 'tag_id',
'unique' => true,
'order' => 'Tag.tag ASC'
)
);
}
Method admin_add:
function admin_add()
{
if (isset($this->data))
{
$this->cleanUpFields('Image');
$this->Image->create();
if ($this->Image->save($this->data))
{
$this->Session->setFlash('Image saved');
} else {
$this->Session->setFlash('Image upload failed');
print_r($this->data);
}
}
$copyright_type = $this->Copyright->generateList();
$this->set(compact('copyright_type'));
$subject_type = $this->Subject->generateList();
$this->set(compact('subject_type'));
}
And here is the SQL for my table - I made most of the fields NULL as I
thought that may have been the error at first, since it might not have
been saving a NOT NULL field:
CREATE TABLE `images` (
`id` int(8) unsigned NOT NULL auto_increment,
`filename` varchar(255) default NULL,
`filesize` int(11) default NULL,
`alt` varchar(255) default NULL,
`mimetype` varchar(255) default NULL,
`ext` varchar(255) default NULL,
`subject_id` int(8) default NULL,
`copyright_owner` varchar(255) default NULL,
`copyright_id` int(8) unsigned default '1',
`image_location` varchar(255) default NULL,
`image_date` date default NULL,
`image_notes` text,
`tags` varchar(255) default NULL,
`user_id` int(8) unsigned default NULL,
`created` datetime default NULL,
`modified` datetime default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `filename` (`filename`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
So it keeps failing on saving the image. My upload dir is under
webroot/files/Image, chmod 777 has been applied. Any ideas?
Thanks,
Tane
On 5/31/07, dardosordi <[EMAIL PROTECTED]> wrote:
>
> > Can you give some instructions?
> >
>
> save http://bin.cakephp.org/saved/17539 as app/models/behaviors/
> upload.php
>
> then in your model, ex post:
>
> <?php
> class Post extends AppModel
> {
> var $name = 'Post';
> var $actsAs = array('Upload' => array(
> 'image' =>
> array('dir' => 'img/posts',
>
> 'allowed_mime' => array('image/png', 'image/jpeg', 'image/pjpeg'),
>
> 'allowed_ext' => array('jpg', 'png'),
>
> 'overwrite_existing' => true,
>
> 'create_directory' => true
>
> )
> )
> );
> }
> ?>
>
>
> Because I'm always uploading images and resizing them I tweaked a
> litle this behaviour and put in it some code to make it upload and
> resize behaviour, then I only put it in the behaviours directory an
> use actsAs in my model. Also put some code to clean the mess when
> deleting the Post (delete the image an its thumbs). If you think it
> can be useful for you, then just tell me and I will paste it on the
> bin (http://bin.cakephp.org).
>
>
>
> > Thanks a lot!
>
> You're wellcome.
>
> Bye, Dardo Sordi.
>
> P/D: Nice to meet an itallian, I'm argentinian (with an italian
> grandfather).
>
> > bye
> >
> > Andrea
> >
> > P/D: I'm an Italian speaker...
> >
> > On 30 Mag, 15:51, dardosordi <[EMAIL PROTECTED]> wrote:
> >
> > > Hi Andrea,
> >
> > > I'm using this for file uploading in 1.2 an works like a charm
> >
> > >http://bin.cakephp.org/saved/17539
> >
> > > Here is how it works:
> >
> > >http://blog.chris-partridge.info/2007/03/16/uploadbehavior-is-here/
> >
> > > Hope it helps.
> >
> > > P/D: Are you spanish speaker?
> >
> > > On May 29, 1:48 pm, Andrea <[EMAIL PROTECTED]> wrote:
> >
> > > > Hi to everybody!
> > > > I want to upload a file that I choose from a field of a form. How can
> > > > I do this action?
> > > > With the previous stable Version of Cake I do this, with the aid of
> > > > this extension:http://www.reversefolds.com/articles/show/filehandler
> > > > With this new version the controller always say to me that I don't
> > > > give to it the file.
> >
> > > > In particular I want to upload an image.
> >
> > > > Help me, please :D
> >
> > > > Thanks
> >
> > > > Ps. Sorry for my bad English!
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---