0

I'm using CakePHP 2.1.1 and Miles Johnson's Uploader Plugin v 3.5.
It's working pretty sweet although I think I have a problem when trying to unload the FileValidation behavior.

I have set up both the behaviors Uploader.Attachment and Uploader.FileValidator (see the bottom of the question).
In the afterSave callback I now need to save the Post again to add a Translated field for a different locale.

When I do save again, this seems to cause en error in the FileValidation behavior. I get the error:
failed to open stream: No such file or directory [APP/Plugin/Uploader/Model/Behavior/FileValidationBehavior.php, line 296]
Somehow the Behavior is looking again for the tmp file.
When I do not define the FileValidation behavior at all, all goes well. So I figured to disable the behavior after it has done it's job during regular save(), right before I go for my second save().
In afterSave($created) I therefore state

$this->Behaviors->unload('FileValidation');
$this->save($data);

The error disappears, but I get 4 warnings in return:

Warning (512): Could not find validation handler maxWidth for file [CORE/Cake/Model/Model.php, line 3155]  
Warning (512): Could not find validation handler maxHeight for file [CORE/Cake/Model/Model.php, line 3155]
Warning (512): Could not find validation handler filesize for file [CORE/Cake/Model/Model.php, line 3155]
Warning (512): Could not find validation handler required for file [CORE/Cake/Model/Model.php, line 3155]

I also tried $this->Behaviors->disable('FileValidation') but to no avail. Is this a bug in the Behavior (not properly unloading itself) or am I not properly handling the unload?

kind regards, Bart

The behavior setup:

public $actsAs = array('Uploader.Attachment' => array(
        'file' => array(
            'name'      => 'uniqueFilename',    // Name of the function to use to format filenames
            'baseDir'   => APP,         // See UploaderComponent::$baseDir
            'uploadDir' => 'webroot/img/upload/',           // See UploaderComponent::$uploadDir
            'dbColumn'  => 'uploadPath',    // The database column name to save the path to
            'importFrom'    => '',          // Path or URL to import file
            'defaultPath'   => '',          // Default file path if no upload present
            'maxNameLength' => 30,          // Max file name length
            'overwrite' => false,       // Overwrite file with same name if it exists
            'stopSave'  => true,        // Stop the model save() if upload fails
            'transforms'    => array(),     // What transformations to do on images: scale, resize, etc
            's3'        => array(),     // Array of Amazon S3 settings
            'metaColumns'   => array(       // Mapping of meta data to database fields
                'ext' => 'ext',
                'type' => 'type',
                'size' => 'size',
                'group' => 'group',
                'width' => 'width',
                'height' => 'height',
                'filesize' => 'size',
                'name'=>'name'
            )
        )
    ),
    'Uploader.FileValidation' => array(
        'file' => array(
            'maxWidth' => array(
                'value' => 1000,
                'error' => 'Image too wide. Max 1000px'
            ),
            'maxHeight' => array(
                'value' => 1000,
                'error' => 'Image too high. Max 1000px'
            ),
            'extension' => array(
                'value' => array('gif', 'jpg', 'png', 'jpeg'),
                'error' => 'Mimetype incorrect',
            ),
            'filesize' => array(
                'value' => 1048576,
                'error' => 'Filesize too high. Max 1 MB'
            )
        )
    )
);
Bart Gloudemans
  • 1,201
  • 12
  • 27

2 Answers2

0

Not directly related, but are you game to try another file upload plugin? This one might do the trick: http://bakery.cakephp.org/articles/srs2012/2012/03/12/ajaxmultiupload_plugin_for_cake_2_0_x_and_2_1

Suman
  • 9,221
  • 5
  • 49
  • 62
0

Not sure if this will fix yours but I found (for some reason I don't know why) this error gets thrown if you don't have debug set to 0 in your Config/core.php

Collin White
  • 640
  • 1
  • 11
  • 27