Skip to content

Commit

Permalink
some stuff for uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Feb 17, 2010
1 parent 0278a9a commit 2efc31d
Show file tree
Hide file tree
Showing 5 changed files with 1,497 additions and 0 deletions.
58 changes: 58 additions & 0 deletions extensions/meio_upload/README.markdown
@@ -0,0 +1,58 @@
# MeioUpload 2.0 Behavior Plugin

This behavior provides to upload files in your application, as well as the possibility to translate the error message (originally only in portuguese) and the use of phpThumb as a better thumbnail generator.

You can also use it in No-DB mode, which means that no data for the upload is stored within the database. You can further this by setting `var $useTable = false` in the model, which will both trigger No-DB mode AND allow quick uploads.


## Installation
- Clone from github : in your behaviors directory type `git clone git://github.com/jrbasso/MeioUpload.git plugins/meio_upload`
- Add as a git submodule : in your behaviors directory type `git submodule add git://github.com/jrbasso/MeioUpload.git plugins/meio_upload`
- Download an archive from github and extract it in `plugins/meio_upload`

* If you require thumbnails for image generation, download the latest copy of phpThumb and extract it into your vendors directory. Should end up like: /vendors/phpThumb/{files}. (http://phpthumb.sourceforge.net)

## Usage
In a model that needs uploading, replace the class declaration with something similar to the following:

<?php
class Image extends AppModel {
var $name = 'Image';
var $actsAs = array(
'MeioUpload.MeioUpload' => array('filename')
);
}
?>

You also need to specify the fields in your database like so
<pre>
`` CREATE TABLE `images` (``
`` `id` int(8) unsigned NOT NULL auto_increment,``
`` `filename` varchar(255) default NULL,``
`` `dir` varchar(255) default NULL,``
`` `mimetype` varchar(255) NULL,``
`` `filesize` int(11) unsigned default NULL,``
`` `created` datetime default NULL,``
`` `modified` datetime default NULL,``
`` PRIMARY KEY (`id`)``
`` ) ENGINE=MyISAM DEFAULT CHARSET=utf8;``
</pre>

Create your upload view, make sure it's a multipart/form-data form, and the filename field is of type 'file':

<?php
echo $form->create('Image', array('type' => 'file'));
echo $form->input('filename', array('type' => 'file'));
echo $form->input('dir', array('type' => 'hidden'));
echo $form->input('mimetype', array('type' => 'hidden'));
echo $form->input('filesize', array('type' => 'hidden'));
echo $form->end('Submit');
?>
You'll want to include any other fields in your Model as well :)

Make sure your directory (app/webroot/uploads/image/ in this case, image changes to the name of your model) is at least CHMOD 775, also check your php.ini MAX_FILE_SIZE is enough to support the filesizes you are uploading (default in the behavior is 2MB, can be configured)

The behavior code will save the uploaded file's name in the 'filename' field in database, it will not overwrite existing files, instead it will create a new filename based on the original plus a counter. For thumbnails, when the file is uploaded, it will automatically create 3 thumbnail sizes (this can be configured) and prepend the name to the thumbfiles as directories(i.e. app/webroot/uploads/image/image_001.jpg will produced app/webroot/uploads/thumb/small/image/image_001.jpg, app/webroot/uploads/thumb/medium/image/image_001.jpg, app/webroot/uploads/thumb/large/image/image_001.jpg)

### Deleting an uploaded file while keeping the record
Flag the file for deletion by setting `data[Model][filename][remove]` to something non-empty, e.g. `TRUE`. The uploaded file including possible thumbnails will then be deleted together with adherent database fields upon save. Note that the record will be preserved, only the file meta-data columns will be reset.
87 changes: 87 additions & 0 deletions extensions/meio_upload/locale/fre/LC_MESSAGES/meio_upload.po
@@ -0,0 +1,87 @@
# LANGUAGE translation of CakePHP Application
# Copyright YEAR NAME <EMAIL@ADDRESS>
# No version information was available in the source files.
#
msgid ""
msgstr ""
"Project-Id-Version: MeioUpload\n"
"POT-Creation-Date: 2009-05-21 22:34-0300\n"
"PO-Revision-Date: 2009-09-12 11:17+0100\n"
"Last-Translator: Alexandrine Boissiere <theasta@gmail.com>\n"
"Language-Team: Juan Basso <jrbasso@gmail.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n>1;\n"
"X-Poedit-Language: Portuguese\n"
"X-Poedit-Country: BRAZIL\n"
"X-Poedit-SourceCharset: utf-8\n"

#: \models\behaviors\meio_upload.php:149
msgid "This field has not been defined between the parameters of MeioUploadBehavior."
msgstr "Ce champ n'a pas été défini dans les paramètres du behavior MeioUpload."

#: \models\behaviors\meio_upload.php:152
msgid "The directory where the file would be placed there or is protected against writing."
msgstr "Le dossier dans lequel le fichier doit être copié n'existe pas ou est protégé en écriture."

#: \models\behaviors\meio_upload.php:155
msgid "The file can not be empty."
msgstr "Merci de préciser le fichier à uploader."

#: \models\behaviors\meio_upload.php:158
msgid "There were problems in uploading the file."
msgstr "Des problèmes sont survenus lors de l'upload du fichier."

#: \models\behaviors\meio_upload.php:161
msgid "The maximum file size is exceeded."
msgstr "Le poids du fichier est supérieur au maximum accepté."

#: \models\behaviors\meio_upload.php:164
msgid "Invalid file type."
msgstr "Le type du fichier est invalide."

#: \models\behaviors\meio_upload.php:167
msgid "Invalid file extension."
msgstr "L'extension du fichier est invalide."

#: \models\behaviors\meio_upload.php:191
msgid "MeioUploadBehavior Error: The field \"%s\" doesn't exists in the model \"%s\"."
msgstr ""

#: \models\behaviors\meio_upload.php:199
msgid "MeioUploadBehavior Error: The default option must be the filename with extension."
msgstr ""

#: \models\behaviors\meio_upload.php:206
msgid "MeioUploadBehavior Error: The thumbsizes names must be alphanumeric."
msgstr ""

#: \models\behaviors\meio_upload.php:283
msgid "MeioUploadBehavior Error: The max_size option format is invalid."
msgstr ""

#: \models\behaviors\meio_upload.php:299
msgid "MeioUploadBehavior Error: The max_size unit is invalid."
msgstr ""

#: \models\behaviors\meio_upload.php:341
msgid "MeioUploadBehavior Error: The field \"%s\" wasn't declared as part of the MeioUploadBehavior in model \"%s\"."
msgstr ""

#: \models\behaviors\meio_upload.php:365
msgid "MeioUploadBehavior Error: The directory %s does not exist and cannot be created."
msgstr ""

#: \models\behaviors\meio_upload.php:369
msgid "MeioUploadBehavior Error: The directory %s does not exist."
msgstr ""

#: \models\behaviors\meio_upload.php:376
msgid "MeioUploadBehavior Error: The directory %s isn't writable."
msgstr ""

#: \models\behaviors\meio_upload.php:627
msgid "Problems in the copy of the file."
msgstr "Des problèmes sont survenus lors de la copie du fichier."

85 changes: 85 additions & 0 deletions extensions/meio_upload/locale/meio_upload.pot
@@ -0,0 +1,85 @@
# LANGUAGE translation of CakePHP Application
# Copyright YEAR NAME <EMAIL@ADDRESS>
# No version information was available in the source files.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"POT-Creation-Date: 2009-05-21 22:34-0300\n"
"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
"Last-Translator: NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

#: \models\behaviors\meio_upload.php:149
msgid "This field has not been defined between the parameters of MeioUploadBehavior."
msgstr ""

#: \models\behaviors\meio_upload.php:152
msgid "The directory where the file would be placed there or is protected against writing."
msgstr ""

#: \models\behaviors\meio_upload.php:155
msgid "The file can not be empty."
msgstr ""

#: \models\behaviors\meio_upload.php:158
msgid "There were problems in uploading the file."
msgstr ""

#: \models\behaviors\meio_upload.php:161
msgid "The maximum file size is exceeded."
msgstr ""

#: \models\behaviors\meio_upload.php:164
msgid "Invalid file type."
msgstr ""

#: \models\behaviors\meio_upload.php:167
msgid "Invalid file extension."
msgstr ""

#: \models\behaviors\meio_upload.php:191
msgid "MeioUploadBehavior Error: The field \"%s\" doesn't exists in the model \"%s\"."
msgstr ""

#: \models\behaviors\meio_upload.php:199
msgid "MeioUploadBehavior Error: The default option must be the filename with extension."
msgstr ""

#: \models\behaviors\meio_upload.php:206
msgid "MeioUploadBehavior Error: The thumbsizes names must be alphanumeric."
msgstr ""

#: \models\behaviors\meio_upload.php:283
msgid "MeioUploadBehavior Error: The max_size option format is invalid."
msgstr ""

#: \models\behaviors\meio_upload.php:299
msgid "MeioUploadBehavior Error: The max_size unit is invalid."
msgstr ""

#: \models\behaviors\meio_upload.php:341
msgid "MeioUploadBehavior Error: The field \"%s\" wasn't declared as part of the MeioUploadBehavior in model \"%s\"."
msgstr ""

#: \models\behaviors\meio_upload.php:365
msgid "MeioUploadBehavior Error: The directory %s does not exist and cannot be created."
msgstr ""

#: \models\behaviors\meio_upload.php:369
msgid "MeioUploadBehavior Error: The directory %s does not exist."
msgstr ""

#: \models\behaviors\meio_upload.php:376
msgid "MeioUploadBehavior Error: The directory %s isn't writable."
msgstr ""

#: \models\behaviors\meio_upload.php:627
msgid "Problems in the copy of the file."
msgstr ""

87 changes: 87 additions & 0 deletions extensions/meio_upload/locale/pt_br/LC_MESSAGES/meio_upload.po
@@ -0,0 +1,87 @@
# LANGUAGE translation of CakePHP Application
# Copyright YEAR NAME <EMAIL@ADDRESS>
# No version information was available in the source files.
#
msgid ""
msgstr ""
"Project-Id-Version: MeioUpload\n"
"POT-Creation-Date: 2009-05-21 22:34-0300\n"
"PO-Revision-Date: 2009-05-21 22:37-0300\n"
"Last-Translator: Juan Basso <jrbasso@gmail.com>\n"
"Language-Team: Juan Basso <jrbasso@gmail.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n>1;\n"
"X-Poedit-Language: Portuguese\n"
"X-Poedit-Country: BRAZIL\n"
"X-Poedit-SourceCharset: utf-8\n"

#: \models\behaviors\meio_upload.php:149
msgid "This field has not been defined between the parameters of MeioUploadBehavior."
msgstr "Este campo não foi definido entre os parâmetros do MeioUploadBehavior."

#: \models\behaviors\meio_upload.php:152
msgid "The directory where the file would be placed there or is protected against writing."
msgstr "O diretório onde este arquivo seria colocado não existe ou é protegido contra escrita."

#: \models\behaviors\meio_upload.php:155
msgid "The file can not be empty."
msgstr "O arquivo não pode ser vazio."

#: \models\behaviors\meio_upload.php:158
msgid "There were problems in uploading the file."
msgstr "Ocorreram problemas no upload do arquivo."

#: \models\behaviors\meio_upload.php:161
msgid "The maximum file size is exceeded."
msgstr "O tamanho máximo de arquivo foi excedido."

#: \models\behaviors\meio_upload.php:164
msgid "Invalid file type."
msgstr "Tipo de arquivo inválido."

#: \models\behaviors\meio_upload.php:167
msgid "Invalid file extension."
msgstr "Extensão de arquivo inválida."

#: \models\behaviors\meio_upload.php:191
msgid "MeioUploadBehavior Error: The field \"%s\" doesn't exists in the model \"%s\"."
msgstr ""

#: \models\behaviors\meio_upload.php:199
msgid "MeioUploadBehavior Error: The default option must be the filename with extension."
msgstr ""

#: \models\behaviors\meio_upload.php:206
msgid "MeioUploadBehavior Error: The thumbsizes names must be alphanumeric."
msgstr ""

#: \models\behaviors\meio_upload.php:283
msgid "MeioUploadBehavior Error: The max_size option format is invalid."
msgstr ""

#: \models\behaviors\meio_upload.php:299
msgid "MeioUploadBehavior Error: The max_size unit is invalid."
msgstr ""

#: \models\behaviors\meio_upload.php:341
msgid "MeioUploadBehavior Error: The field \"%s\" wasn't declared as part of the MeioUploadBehavior in model \"%s\"."
msgstr ""

#: \models\behaviors\meio_upload.php:365
msgid "MeioUploadBehavior Error: The directory %s does not exist and cannot be created."
msgstr ""

#: \models\behaviors\meio_upload.php:369
msgid "MeioUploadBehavior Error: The directory %s does not exist."
msgstr ""

#: \models\behaviors\meio_upload.php:376
msgid "MeioUploadBehavior Error: The directory %s isn't writable."
msgstr ""

#: \models\behaviors\meio_upload.php:627
msgid "Problems in the copy of the file."
msgstr "Problema na cópia do arquivo."

0 comments on commit 2efc31d

Please sign in to comment.