milesj / uploader

[Deprecated] A CakePHP plugin for file uploading and validating.
MIT License
193 stars 73 forks source link

Cannot unset string offsets in FileValidationBehavior #136

Closed martin-ct closed 11 years ago

martin-ct commented 11 years ago

On php version 5.2 and maybe also lower version I'm getting error " Cannot unset string offsets" in file "Model/Behavior/FileValidationBehavior.php". It happens because of incorrect operation with arrays/strings. For example if you run code like this if (isset($setting['error'])) { on string it returns true (because it will expect an integer value - line 278).

Possible fix is on the line 256 at the beginning of the array with is_array() function: if (!is_array($setting) || !isset($setting['value'])) { $setting = array('value' => $setting); }

milesj commented 11 years ago

How are you defining the rules? There is a specific structure you need to follow.

martin-ct commented 11 years ago
public $actsAs = array(
        'Uploader.FileValidation' => array(
            'name' => array(
                'maxWidth' => 6000,
                'maxHeight' => 6000,
                'extension' => array('gif', 'jpg', 'png', 'jpeg'),
                'type' => 'image',
                'filesize' => 5242880,
                'required' => true
            )
        )
);
milesj commented 11 years ago

What Uploader version are you running since it requires PHP 5.3 and you mentioned 5.2?

martin-ct commented 11 years ago

Yes I am running the latest version. Sorry I didn't noticed the requirement for php 5.3. I was developing on php 5.4.4 but I just tested the implementation on php 5.2 and found that error. I thought it could help. :)

milesj commented 11 years ago

Cool will look into.

Tobse commented 11 years ago

I have the same issue with php 5.3.18. Validation works fine on the developement machine with php 5.4.16 I am running the latest Uploader version as well.

designvoid commented 11 years ago

I can confirm same issue on 5.3.20

milesj commented 11 years ago

Interesting. Probably why I never saw it was because I test on 5.4. Will take a look this weekend.

milesj commented 11 years ago

Fixed.