Pregunta

I've installed Miles Johnson's Uploader plugin and set it up with one of my models and got it working perfectly. Very nice.

Then I went and set it up on another model with almost identical code [the only difference is the upload path] and it won't work on the second model. When I submit the form the plugin doesn't seem to notice; I get an SQL error from an attempt to insert the POST file array straight into the DB.

Here is the code. [Other than this the plugin is imported in the bootstrap]

public $actsAs = array( 
    'Uploader.Attachment' => array(
        'photo' => array(
            'name'      => 'formatFileName',    
            'uploadDir' => '/uploads/uses/img/',
            'dbColumn'  => 'photo',
            'maxNameLength' => 30,
            'overwrite' => true,
            'stopSave'  => true,
            'allowEmpty'    => false,
            'transforms' => array(
                array('method' => 'resize', 'width' => 240, 'dbColumn' => 'photo_thumb'))
        )
    ),
    'Uploader.FileValidation' => array(
        'fileName' => array(
            'extension' => array('gif', 'jpg', 'png', 'jpeg'),
            'required'  => true
        )
    )
    );

This is on the model that is not uploading and the only difference is the uploadDir.

Does the plugin only work on one model? Any clues? thnx :}


Edit for extra clarity

Here is my view code:

echo $this->Form->create('Use', array('type' => 'file'));
echo $this->Form->input('Use.photo', array('type' => 'file'));
echo $this->Form->input('Use.desc', array('rows' => '3', 'label' => 'Description'));
echo $this->Form->end('Add to Gallery');

And here is my controller code:

public function add() { 
        if ($this->request->is('post')) {       
            $this->Use->set('user_id', $this->Auth->user('id'));        
            if ($this->Use->save($this->request->data)) {
                $this->Session->setFlash('Your Use has been saved.');
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash('Unable to add your Use.');
            }
        }
    }
¿Fue útil?

Solución 2

After checking thru the code with Alessandro [thank you :)] I found the problem.

If you look in the View and Controller code you can see that the model is named 'Use'. This was the problem, as Use is a loaded word in PHP and I shouldn't have used it for a model name.

I renamed the model to Outcome and now the Uploader works perfectly.

Otros consejos

The plugin doesn't work in only one model. You can add more uploader into your site. The model seems to be good, I suggest you to see into your form to see if you have create the form in the right way into your view (is imporant to put into your form: 'type' => 'file' example:

echo $this->Form->create('Product', array ('class' => 'form', 'type' => 'file')); 
echo $this->Form->input('ModelImage.filename', array('type' => 'file'));
echo $this->Form->submit('Add Image', array('id'=>'add_image'));
echo $this->Form->end();

Or the problem is the name Use try to change the name with another

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top