Tags:
attachments1Add my vote for this tag component1Add my vote for this tag forms1Add my vote for this tag twiki_application1Add my vote for this tag twiki_form_field1Add my vote for this tag create new tag
, view all tags

FileUploadPlugin

Make TWiki forms able to handle file uploads

Introduction

This plugin make TWikiForms capable of uploading files in edit mode. The uploaded file is attached to the page. This can be useful in situations, where the form and the uploaded file are linked. For example, where people have to fill in an application form and have to attach their picture.

Features

  • Checks filesize of the file.
  • Use regular expressions to see if the filename matches. (To check for extension, special format etcetera)
  • Multiple file fields in one form.
  • Checks filemagic against extension.

Syntax

This plugin adds a file type to TWikiForms:

Type Description Size Value
file screenshot File upload form field, to upload an attachment to the topic when saving the form. Text box width in number of characters  

Form definition:

| *Name* | *Type* | *Size* | *Values* | *Tooltip message* | *Attributes* |
| File   | file   | 10     |          |                   | (see below) |

The attribute field is used to pass parameters to FileUploadPlugin, format parameter{value}:

Parameter Possible Value Example What it does
maxsize [0-9]+[KMG]?, where K = kilo, M = mega and G = giga. Not the kibi stuff. So a kilobyte is 1024 bytes. The M might interfere with TWiki's mandatory flag M, use K instead of M. If maxsize is provided, pattern has to be specified as well. maxsize{10M} Check if the file is smaller than the maxsize.
pattern Regular expression pattern{/\w{0,255}?.jpg/i} Check if the filename matches the pattern.
mime_check rename, delete mime_check{rename} Check whether the extension implies the mimetype, if not delete in case of value=delete or rename to the right extension in case of value=rename. When this parameter is omitted no checks are done.

Note: mime_check is still beta.

The parameters should be separated by a space. For example:

| *Name* | *Type* | *Size* | *Values* | *Tooltip message* | *Attributes* |
| File   | file   | 10     |          |                   | maxsize{500K} pattern{\w+.png} |

Regular expressions

It is now possible to use regular expressions like:

pattern{/\w+.png/ig}
The old syntax is still usable:
pattern{\w+.png}
There are some restrictions, you can't use:
pattern{(?{ system('rm -Rf /')})}

It get filtered out for obvious reasons smile

Configuration

It is recommended to use your apache magic file (eg: /etc/apache2/magic) instead of the standard file of File::Magic. To configure this, you have to set in LocalSite.cfg the following setting:

 $TWiki::cfg{Plugins}{FileUploadPlugin}{MagicFile} = '/etc/apache2/magic';

Examples

For example a website with historical information of buildings. It would be nice to add a picture. Of course this can be done by the attach button, but it is more user friendly to add the standard form to the template and include a field where the user can upload his picture. It is also more easy to control, what kind of picture the user uploads and how the filename has to be formatted. Here the user should format his file like: NAME-DDMMYY.jpg, which is impossible with the attach button. You can also set different filesize limits on different formats. In this example, movie files are restricted to a filesize of 100MB, but pictures are restricted to 10MB.

Please type your description here. Use the appropiate format, NAME-DDMMYY.ext, if you upload a picture or a movie.

| *Name*   | *Type* | *Size* | *Values* | *Tooltip message* | *Attributes*                                        | 
|   Name   |  text  |   10   |          |  Building name    |                                                     |
| Address  |  text  |   10   |          |Address of building|                                                     |
|Build Year|  text  |   10   |          |When is it build?  |                                                     |
| Picture  |  file  |   10   |          |max size 10MB,     |pattern{/\w+-\d{6}?.jpg/i} maxsize{10M}              |
| Movie    |  file  |   10   |          |max size 100MB     |pattern{/\w+-\d{6}?.(?:mpg|avi|wmv)/i} maxsize{100M} |

Plugin Installation Instructions

Note: You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the plugin on the TWiki server.

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatmd5 FileUploadPlugin.md5 r9 r8 r7 r6 r5 manage 0.2 K 2016-02-14 - 01:10 PeterThoeny  
Compressed Zip archivetgz FileUploadPlugin.tgz r10 r9 r8 r7 r6 manage 15.2 K 2016-02-14 - 01:10 PeterThoeny  
Compressed Zip archivezip FileUploadPlugin.zip r15 r14 r13 r12 r11 manage 18.0 K 2016-02-14 - 01:10 PeterThoeny  
Unknown file formatEXT FileUploadPlugin_installer r4 r3 r2 r1 manage 3.7 K 2016-02-14 - 01:10 PeterThoeny  
Edit | Attach | Watch | Print version | History: r23 < r22 < r21 < r20 < r19 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r23 - 2016-02-14 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2016 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.