MultiUpload
Questions answered by this recipe
- How can I upload multiple files to PmWiki at once?
Description
MultiUpload adds an option to the upload page to "Extract archive contents". If the uploaded file is a valid (zip) archive, this will extract the files from the archive and add them to the current page as if they were individually uploaded.
To install this recipe
- download multiupload.phpΔ to your cookbook directory
- add the following line to your configuration file:
include_once("$FarmD/cookbook/multiupload.php");
Notes
MultiUpload requires PHP 5 ZipArchive support and will abort if that isn't available.
Verification of uploaded files when using MultiUpload is not done using the function defined in $UploadVerifyFunction
(UploadVerifyBasic
by default) but with two included functions (UploadVerifyArchive
and UploadVerifyArchiveEntry
) which replicate the default function's checks.
You may want to check your
and other file size limits, as they'll apply to the whole archive as well as individual files within it.
$UploadMaxSize
Since this modifies the upload form, you may be interested to add the following (or something similar) to your Site.UploadQuickReference page:
How it works
When a file is uploaded with 'extract'
set on, HandlePostMultiUpload
will first check that the file is valid (eg. that its size doesn't go over any set limit), then opens it using the ZipArchive class. Entries in the archive are processed sequentially, stripping any directory specifications, wikifying the name using MakeUploadName
and verifying the file before extracting it into the current uploads directory.
MultiUpload will stop at the first error, but won't undo any changes made before then, ie. an error on the fifth file in an archive will still result in four saved files.
Alternative form layout
The default layout set by MultiUpload is very similar to the default upload form layout. Here's an alternative form layout (the one I actually use) that you can add to you configuration file. It has wider edit fields and tooltip explanations. It's rather hard to get the layout to work decently due to the different file input implementations in different browsers.
$PageUploadFmt = array("<h2>Attachments for {\$Group} group</h2> <h3 class='wikimessage'>\$UploadResult</h3> <div id='wikiupload' class='wikibox' style='margin:0 40px;padding:20px;'> <form enctype='multipart/form-data' action='{\$PageUrl}' method='post'> <input type='hidden' name='n' value='{\$FullName}' /> <input type='hidden' name='action' value='postmultiupload' /> <table border='0' style='margin:0 auto;'><tr> <td align='right'><acronym title='Browse to the file on your computer that you want to upload.'>File to upload</acronym> </td> <td><input name='uploadfile' type='file' size='30' /></td> </tr><tr> <td align='right'><acronym title='Optional, default is the uploaded filename. Filename requires extension.'>Name on server</acronym> </td> <td><input type='text' name='upname' value='\$UploadName' size='30' /></td> </tr><tr> <td colspan='2' align='right'><label><acronym title='Check to upload multiple files inside a zip file.'>Extract archive contents</acronym> <input type='checkbox' name='extract' id='extract' /></label> <input type='submit' value='Upload' style='margin-left:5em;' /></td> </tr></table></form></div>", 'wiki:$[{$SiteGroup}/UploadQuickReference]');
Also note that this variable is set in MultiUpload using SDV, so including the script file upload.php before including multiupload.php requires you to define your own $PageUploadFmt.
Release Notes
- 2007-11-27 - bugfix: UploadVerifyArchiveEntry
- 2007-11-26 - first release
See Also
- UploadForm Alternative file upload form using
(:input file:)
- CompressedUploads Modify scripts/upload.php to work with bzip2 archives
- Attachtable Actions to rename, delete & restore deleted attachments, as well as an attachlist replacement to use those actions, show file types and list attachment references.
- DragDropMultiUpload Allow authors to upload files by simply dropping them into the wiki page
Contributors
Comments
See discussion at MultiUpload-Talk
I put this together in less than a day, so be aware that it may fail in odd ways. The ZipArchive requirement is due to that being available on the server I use and its interface looking relatively simple. I'm actually not sure what filetypes it'll accept, the only one I've bothered to check so far is zip
, for which at least 'deflate' and 'BZip2' compression methods work. I'm quite willing to listen to suggestions for how else this could be done. --EemeliAro November 26, 2007, at 04:36 PM
Hi. Can you upload some pmwiki page code that makes this work? Also - anyone foresee a way to make this work with PHP v.4.4.8 (ZLib 1.2.1.2)? overtones99 February 27, 2008, at 12:50 AM
User notes? : 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.