UploadForm
(:input file:)
Questions answered by this recipe
How can I create an alternative to the default pmwiki upload page?
Description
UploadForm adds action 'postupload2' for use in alternative upload forms.
include_once("$FarmD/cookbook/uploadform.php");
Create an alternative upload form using Forms markup and the (:input file:)
markup.
An example for a simple form (not enabled on this page):
>>frame<< (:if auth upload:) (:messages:) (:input form enctype='multipart/form-data' action={*$PageUrl}:) (:input hidden action postupload2:) (:input pmtoken:)(:input hidden n {*$FullName}:) ||width=100% || File to upload:||(:input file uploadfile size=50:) || || Optionally rename file as:||(:input text upname size=50:) (:input submit post Upload:) || (:input end:) (:else:)You need to login before you can upload [[{*$FullName}?action=login|login]](:if:) >><< |
This form will keep the user on the page, and not redirect to the default uploads form. The script uses the standard file verification function. The form will display the upload result via the (:messages:)
markup.
To show a list of uploaded files (attachments), use markup (:attachlist:)
, or for an alternative list with a tabulated, cleaner look use markup (:filelist:)
(see FileList recipe for this).
Firefox drag-and-drop-files support
You can add support for drag-and-drop multiple files in Firefox by installing the dragdropupload Firefox extension.
To create an upload form which can handle multiple files dropped on it, build a form like this example:
>>frame<< (:messages:) (:input form enctype='multipart/form-data' action={*$PageUrl}:) (:input hidden action postupload2:) ''This input box accepts multiple files dropped on it, which cannot be renamed'' ||width=100% || File(s) to upload:||(:input dropfiles uploadfiles size=50:) || || ||(:input submit post "Upload Files":) || (:input end:) >><<
Note the file control is input dropfiles and its name is uploadfiles, not uploadfile. This makes it possible to have both forms of this type and of the single file input type shown first.
Notes
uploadform.php
includes a modification of the HandlePostUpload function from scripts/upload.php.
Enssure that in config.php
you secure the file upload action, ie
$DefaultPasswords['postupload2'] = crypt('secret');
Since PmWiki 2.3.23 you have to add (:input pmtoken:)
, see here.
Release Notes
- 2009-08-26: Fixed bug so upload password gets checked.
- 2007-09-03: Added support for drag-and-dropping multiple files (for Firefox which got the dragdropuploads extension installed). Improved message display of upload results.
- 2007-09-01: initial release.
Comments
- 2009-08-25: Security problem... a non-priv user can upload files.
Fixed now. HansB August 26, 2009, at 05:52 AM
See Also
- DragDropMultiUpload Allow authors to upload files by simply dropping them into the wiki page
- MultiUpload Upload multiple files at once by packing them in a zip archive & extracting them on the server
Contributors
User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.