Hi Brad,
Well in that $this->data it looks like you're not actually uploading
the file. Make sure your form tag includes multipart.
$form->create('Model', array('type' => 'file'));
In regards to the detach and reattach behavior settings, a small
example would be like:
function add(){
if(!empty($this->data)){
$this->Model->Upload->Behaviors->detach('FileUpload.FileUpload');
$this->Model->Upload->Behaviors->attach('FileUpload.FileUpload',
array('fileTypes' => array('mp3')));
$this->Model->saveAll($this->data);
}
}
Here is the API for attach and detach:
http://api13.cakephp.org/class/behavior-collection#method-BehaviorCollectionattach
Hope that helps,
Nick
On Jul 12, 6:27 pm, bradmaxs <[email protected]> wrote:
> Hi Nick,
>
> Sorry for the lapse but was busy with other projects.
>
> The issue is that the file is going to a different folder that has
> nothing to do with this model or controller or form?? The record is
> being saved to the DB in the correct table but is getting uploaded to
> the a directory that is specified in another models controller and
> there are no relationships between the two. What seems strange is
> that this is the only model it is happening for and I have 3 other
> models where it works correctly.
>
> You said different upload directories are not supported yet but
> wouldn't that not matter since I am using it as a stand alone
> component on each different model? Meaning, it is declared in the
> Model in the actsAs var.
>
> "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."
>
> I am sorry to be a newbie but could you give me a small example if it
> is small or point me in the direction of how to do that?
>
> Also - I am trying to upload an mp3 file on another model and nothing
> is happening. The browser acts like it is doing something and then
> comes back saying that the file has been saved but the record is not
> there and the file is not uploaded.
>
> I am using the same ADD function that works for all the other uploads
> and in the model I have this.
>
> I have printed out the data and it seems that the type and size are
> not being read?? The funny thing is is I have required set to false
> and the record is still not saving even if the file field is left
> blank.
>
> Here is what I have for the actsAs
>
> var $actsAs = array(
> 'FileUpload.FileUpload' => array(
> 'uploadDir' => 'files/audio',
> 'fields' => array('name' => 'file_url', 'type' =>
> 'file_type', 'size' => 'file_size'),
> 'allowedTypes' => array('mp3' => array('audio/mp3', 'audio/
> mpeg', 'audio/x-mpeg', 'audio/mp3', 'audio/x-mp3', 'audio/mpeg3',
> 'audio/x-mpeg3', 'audio/mpg', 'audio/x-mpg', 'audio/x-mpegaudio')),
> 'required' => false, //default is false, if true a
> validation error would occur if a file wsan't uploaded.
> 'maxFileSize' => '10485760', //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)
> )
> );
>
> Array
> (
> [_Token] => Array
> (
> [key] => d3ac1dcc08333b2c6ce2243d0f95abe72def82d8
> [fields] => 6cbbe5f975cba1b5eb40acf446944f4089d8f111%3An
> %3A1%3A%7Bv%3A0%3Bf%3A13%3A%22Nhqvb.hfre_vq%22%3B%7D
> )
>
> [Audio] => Array
> (
> [user_id] => 1
> [title] => new
> [description] => new
> [price] => .99
> [file] => Array
> (
> [name] => norib.mp3
> [type] =>
> [tmp_name] =>
> [error] => 1
> [size] => 0
> )
>
> )
>
> [AudioCategory] => Array
> (
> [AudioCategory] => Array
> (
> [0] => 3
> [1] => 4
> )
>
> )
>
> )
>
> Nick, thanks again for all of your help. I really do appreciate it.
>
> Brad
>
> On Jul 5, 9:44 pm, nurvzy <[email protected]> wrote:
>
>
>
> > 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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
>
> ...
>
> read more »
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 [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