I am glad to show you the MeioUpload Behavior 1.0.1. An improved Upload Behavior for CakePHP 1.2. It makes file uploads as simple as defining a variable.
Features
- Accepts custom directory for files to be uploaded;
- Validates the file extension and mime-type due to the behavior configuration;
- Validates the max file size;
- Allow custom validation rules;
- Allow as many thumbnails formats as you want;
- Allow more then one field to be uploadable, with custom options per field;
- Stores the directory, filesize, and mime-type in the database if the table has these fields;
- Allow the use of default files and deleting files without deleting the entire record;
- Delete files when the record is deleted or updated with a new file;
- Also works in the $model->saveAll method.
Changelog
v1.0.1
- Fixed a bug in the create folder method;
- Now you can use the $validate var of the model to apply the changes to default validation rules;
- Changed the my_array_merge function, now it’s part of the behavior, name arrayMerge;
- Allow use of {DS}, {model} and {field} constants in directory name and fields names;
- Fixed a bug with the replacement of the default names.
v1.0
- Initial release
Any bugs, features suggestions, and english errors, please tell me.

October 5th, 2008 16:37
esse site tem códigos ótimos! tornou minha vida muita mais fácil!
parabéns!
October 5th, 2008 23:23
Obrigado pelo reconhecimento. Qualquer dúvida é só falar.
October 11th, 2008 11:25
Nice work. You have done a fine job improving upon the work of the previous authors. A few comments: - Didn’t core’s Set::merge work for you instead of you custom recursive merge function ? - Not that it matters much but I think a more appropriate location to merge validation rules with the model’s $validate would be beforeValidate callback. - You should submit this fine piece of work to the bakery. Its deserves more exposure
October 11th, 2008 19:46
Thank’s for the comment, I will take note of these suggestions and analyze the possibility of implementing them. I saw the Set::merge function a little while after publishing the behavior but already changed the code to use it, I will publish it soon.
About the validation, I’m thinking about changing some things in it. Maybe use the var $validate of the model to apply the validation rules. I think it is more related to the work the framework is doing.
And about the bakery, I’m trying to have time to do this. Anyway, thanks for the comment again.
October 23rd, 2008 05:19
Comments round 2
In beforeSave when attempting to move uploaded file don’t set the error message directly to validationErrors array . Instead use the Model->invalidate function. Many people override this function for il8n and translate the message string first before setting to validationErrors.
Not important but declaring the default validation errors twice as $default_options['validations'] and as $default_validations seems a bit redundant. You can just have $default_options['validations'] and assign it to $default_validations in setup() if needed.
October 23rd, 2008 09:54
Hehe
thanks for the help. Fell free to make as many rouds as you want. I will see this invalidate function. And about the arrays, I will keep just the $default_validations, Since it merges both. I don’t removed the $default_options['validations'] just to keep the backwards compatibility.
October 23rd, 2008 13:42
Nice work, I was suffering from corrupted uploads on MAMP running OSX10.5.3. Inserting this block of code at line 636 to set the permissions of the uploaded file fixed the problem:
October 23rd, 2008 23:08
Kanoa, thanks for the contribution, I will add this piece of code in the behavior.
October 26th, 2008 07:12
Setting fixed file permissions is not a good idea. Keep it configurable so that permissions can be set as required based on server needs.
October 27th, 2008 12:57
Hmm, good idea. I will do this. An option, if empty, don’t set permissions, else set the permission based in this string. The default will be it empty.
September 7th, 2009 14:20
Olá Vinicius…. Muito bom o seu behavior, sou um novo aventureiro do CakePHP, meu problema é o seguinte tenho que enviar uma lista de imagens de uma só vez pelo seu Behavior, por isso optei por um flash que cria a lista e as envia. As informações do arquivo fica em um $_FILES['Filedata'].
Meu Código: if (!empty($_FILES["Filedata"])) { $this->Imagem->create(); $this->data['Imagem']['imagem']['name'] = $_FILES['Filedata']['name']; $this->data['Imagem']['imagem']['type'] = $_FILES['Filedata']['type']; $this->data['Imagem']['imagem']['tmp_name'] = $_FILES['Filedata']['tmp_name']; $this->data['Imagem']['imagem']['error'] = $_FILES['Filedata']['error']; $this->data['Imagem']['imagem']['size'] = $_FILES['Filedata']['size']; $this->Imagem->save($this->data); }
Mas ele não resulta em nada. Não guarda nada em DB nem faz upload.
Obrigado