Monday, July 5, 2010

Re: Nick Baker's FileUpload

Hi,

Well that looks A-OK to me. Error code 0 is a good thing. So the
issue it is not being saved to the file system or that it's not in the
directory you expected it to be? Different upload directories is not
officially supported yet but it is slated to be in the next release.
The tricky part being how the helper decides where a file is based on
which model configuration it decides to use. What's probably
happening is depending on how your models are being constructed, and
instantiated in which order the configuration for each model is
overwriting the previous configuration. In the next release each
configuration will be cached on a model key as to not conflict with
one another. However, until then, a patch to make it work the way you
expect would be to unbind the behavior and then rebind it before the
final save, forcing correct configuration to be used at that save.

This solution is not ideal, I expect to have the next release ready
this month.

Hope that helps,
Nick

On Jul 5, 7:55 pm, bradmaxs <b...@pezzano.com> wrote:
> Here it is!
>
> Array
> (
>     [_Token] => Array
>         (
>             [key] => 41294a9d9841267a9d32777ebd041179ba6a0a89
>             [fields] => e26baca1e6f629a524452b4f7a8e3fa7f8f45a9e%3An
> %3A0%3A%7B%7D
>         )
>
>     [Egaragead] => Array
>         (
>             [website] =>http://www.puddly.com
>             [description] => Description
>             [position] => 5
>             [file] => Array
>                 (
>                     [name] => outtamustard.jpg
>                     [type] => image/jpeg
>                     [tmp_name] => /tmp/phpubfDP3
>                     [error] => 0
>                     [size] => 48661
>                 )
>
>         )
>
> )
>
> On Jul 5, 6:44 pm, nurvzy <nur...@gmail.com> wrote:
>
>
>
> > Ok.  Thanks for sharing that, I don't see any glaringly obvious
> > culprits in your configuration.  How are you passing data into your
> > Egaragead model?  Would you mind running a debug($this->data) before
> > you pass it to Egaragead->save() and post it?
>
> > Thanks,
> > Nick
>
> > On Jul 5, 7:18 pm, bradmaxs <b...@pezzano.com> wrote:
>
> > > Hey Nick,
>
> > > Thank you. It is great right out of the box.
>
> > > I am using actsAs for all of them actually.
>
> > > Here are the three that are goofing with me.
>
> > > Upon further exploration as noted above I removed the cshow model and
> > > it started going into the artist_preference model??
>
> > > Then I removed that one and it didn't upload at all.  I put the cshow
> > > back up and voila, right back into the folder specified for that
> > > model.  So weird huh?
>
> > > Thanks again.
>
> > > Here is the model code.
>
> > > cshow:
>
> > > class Cshow extends AppModel {
> > >         var $name = 'Cshow';
> > >         var $actsAs = array(
> > >         'FileUpload.FileUpload' => array(
> > >                 'uploadDir' => 'files/img_thegarage',
> > >                 'fields' => array('name' => 'image', 'type' => 'image_type',
> > > 'size' => 'image_size'),
> > >                 //'allowedTypes' => array('pdf' => array('application/
> > > pdf')),
> > >                 'required' => false, //default is false, if true a
> > > validation error would occur if a file wsan't uploaded.
> > >                 'maxFileSize' => '2097152', //bytes OR false to turn off
> > > maxFileSize (default false)
> > >                 'unique' => true //filenames will overwrite existing files
> > > of the same name. (default true)
> > >                 //'fileNameFunction' => 'sha1' //execute the Sha1 function
> > > on a filename before saving it (default false)
> > >         )
> > >     );
>
> > > I have some validation and it hasMany cshow_comment.
>
> > > artist_preference
>
> > > class ArtistPreference extends AppModel {
> > >         var $name = 'ArtistPreference';
> > >         var $actsAs = array(
> > >         'FileUpload.FileUpload' => array(
> > >                 'uploadDir' => 'files/img_artisticon',
> > >                 'fields' => array('name' => 'image', 'type' => 'image_type',
> > > 'size' => 'image_size'),
> > >                 //'allowedTypes' => array('pdf' => array('application/
> > > pdf')),
> > >                 'required' => false, //default is false, if true a
> > > validation error would occur if a file wasn't uploaded.
> > >                 'maxFileSize' => '2097152', //bytes OR false to turn off
> > > maxFileSize (default false)
> > >                 'unique' => true //filenames will overwrite existing files
> > > of the same name. (default true)
> > >                 //'fileNameFunction' => 'sha1' //execute the Sha1 function
> > > on a filename before saving it (default false)
> > >         )
> > >     );
>
> > > validation again and it belongsTo user and band
>
> > > AND THE CULPRIT:
>
> > > egaragead
>
> > > class Egaragead extends AppModel {
> > >         var $name = 'Egaragead';
> > >         var $actsAs = array(
> > >         'FileUpload.FileUpload' => array(
> > >                 'uploadDir' => 'files/img_egarageads',
> > >                 'fields' => array('name' => 'image', 'type' => 'image_type',
> > > 'size' => 'image_size'),
> > >                 //'allowedTypes' => array('pdf' => array('application/
> > > pdf')),
> > >                 'required' => false, //default is false, if true a
> > > validation error would occur if a file wsan't uploaded.
> > >                 'maxFileSize' => '2097152', //bytes OR false to turn off
> > > maxFileSize (default false)
> > >                 'unique' => true //filenames will overwrite existing files
> > > of the same name. (default true)
> > >                 //'fileNameFunction' => 'sha1' //execute the Sha1 function
> > > on a filename before saving it (default false)
> > >         )
> > >     );
>
> > > took out validation for now - no relations.
>
> > > On Jul 5, 6:10 pm, nurvzy <nur...@gmail.com> wrote:
>
> > > > Hi Bradmax,
>
> > > >   First, thanks for using the plugin.  Sorry to hear of your
> > > > troubles.  Is your ad model the only model that is using actsAs
> > > > configuration, (ie the rest using the component?).   Would you mind
> > > > showing me how you have it (and the working models) configured?
>
> > > > Thanks,
> > > > Nick
>
> > > > On Jul 5, 6:07 pm, bradmaxs <b...@pezzano.com> wrote:
>
> > > > > UPDATE: I removed the show model and it is going to another one in
> > > > > it's place.  What have I done...
>
> > > > > On Jul 5, 4:54 pm, bradmaxs <b...@pezzano.com> wrote:
>
> > > > > > Hi All,
>
> > > > > > I have been using Nick Baker's FileUpload with much success.
>
> > > > > > Except for one incredibly strange problem.
>
> > > > > > I am using the plugin for about 8 models and each has a different
> > > > > > upload folder/destination.
>
> > > > > > All of them are working fine except for the ad model.
>
> > > > > > Initially I was having trouble getting the ads add form to upload the
> > > > > > image to the specified folder.  The record was being saved but the
> > > > > > image was not getting uploaded.  The show model was working great so I
> > > > > > copied the actsAs code and pasted in my ad model. I also changed the
> > > > > > path to the upload folder for the ad model. All of a sudden the images
> > > > > > were being uploaded to the shows destination folder even though that
> > > > > > is not the folder specified in my ad model???
>
> > > > > > For the life of me I can't figure this out.
>
> > > > > > The ad model is using the show model's upload directory path??
>
> > > > > > I have tried everything. I have cleared the cache a million times.
>
> > > > > > I removed the show model and cleared the cache and it STILL did it.
>
> > > > > > Has anyone heard of this?  Is it actsAs that is goofing me?  Am I
> > > > > > missing something?  I just can't see how I can remove the show model
> > > > > > with the destination path it is using (god knows why), clear all the
> > > > > > cache folders (models, persistent and views) and it still happens.
>
> > > > > > I am in crazy bizzaro world.
>
> > > > > > Please help.

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: