PmWiki /
Uploads Administration
PmWiki includes a script called upload.php that allows users to upload files to the wiki server using a web browser. Uploaded files (also called attachments) can then be easily accessed using markup within wiki pages. This page describes how to install and configure the upload feature.
Some notes about securityPmWiki takes a somewhat paranoid stance when it comes to the uploads feature. Thus, the default settings for uploads tend to try to restrict the feature as much as possible:
$EnableUploadOverwrite = 0;
Basic installationThe upload.php script is automatically included from stdconfig.php if the$EnableUpload variable is true in config.php. In addition, config.php can set the $UploadDir and $UploadUrlFmt variables to specify the local directory where uploaded files should be stored, and the URL that can be used to access that directory. By default, $UploadDir and $UploadUrlFmt assume that uploads will be stored in a directory called uploads/ within the current directory (usually the one containing pmwiki.php). In addition, config.php should also set a default upload password (see PasswordsAdmin).
Thus, a basic config.php for uploads might look like:
<?php if (!defined('PmWiki')) exit(); ## Enable uploads and set a site-wide default upload password. $EnableUpload = 1; $DefaultPasswords['upload'] = crypt('secret'); $UploadDir = "/home/john/public_html/uploads"; $UploadUrlFmt = "http://www.john.com/~john/uploads"; $UploadPrefixFmt . This determines whether all uploads go in one directory for the site, an individual directory for each group, or an individual directory for each page. The default is to organize upload by group.
For site-wide uploads, use
$UploadPrefixFmt = '';
$UploadPrefixFmt = '/$FullName'; $UploadPrefixFmt = '/$Group/$Name'; The upload directoryFor the upload feature to work properly, the directory given by $UploadDir must be writable by the web server process, and it usually must be in a location that is accessible to the web somewhere (e.g., in a subdirectory of public_html). Executing PmWiki with uploads enabled will prompt you with the set of steps required to create the uploads directory on your server (it differs from one server to the next). Note that you are likely to be required to explicitly create writable group- or page-specific subdirectories as well!Uploading a fileOnce the upload feature is enabled, users can access the upload form by adding "?action=upload " to the end of a normal PmWiki URL. The user will be prompted for an upload password similar to the way other pages ask for passwords (see Passwords and PasswordsAdmin for information about setting passwords on pages, groups, and the entire site).
Another way to access the upload form to insert the markup "Attach:filename.ext " into an existing page, where filename.ext is the name of a new file to be uploaded. When the page is displayed, a '?-link' will be added to the end of the markup to take the author to the upload page. (See Uploads for syntax variations.)
By default, PmWiki will organize the uploaded files into separate subdirectories for each group. This can be changed by modifying the $UploadPrefixFmt variable. See Cookbook:UploadGroups for details.
Versioning Uploaded FilesPmWiki does not manage versioning of uploaded files by default. However, by setting$EnableUploadVersions =1; an administrator can have older versions of uploads preserved in the uploads directory along with the most recent version.
Restricting uploaded files for groups and pagesUploads can be enabled only for specific groups or pages by using a per group customization. Simply set for those groups or pages where uploading is to be enabled; alternately, set in the config.php file and then set in the per-group or per-page customization files where uploads are to be disabled.
Restricting total upload size for a group or the whole wikiUploads can be restricted to an overall size limit for groups. In the group configuration file (i.e., local/Group.php), add the line$UploadPrefixQuota = 1024000; # limit group uploads to 1000KThis will limit the total size of uploads for that group to 1000k --any upload that pushes the total over the limit will be rejected with an error message. This value defaults to zero (unlimited). Uploads can also be restricted to an overall size limit for all uploads. Add the line $UploadDirQuota = 10240000; # limit total uploads to 10000KThis will limit the total size of uploads for the whole wiki to 10000k --any upload that pushes the total over the limit will be rejected with an error message. This value defaults to zero (unlimited). Restricting uploaded files type and sizeThe upload script performs a number of verifications on an uploaded file before storing it in the upload directory. The basic verifications are described below.
$UploadMaxSize = 100000;
.gif " and ".jpeg " files to 20K, ".doc " files to 200K, and all others to the size given by $UploadMaxSize . The $UploadExtSize array is used to determine which file extensions are valid and the maximum upload size (in bytes) for each file type. For example:
$UploadExtSize['gif'] = 20000; # limit .gif files to 20K
$UploadExtSize['zip'] = 0; # disallow .zip files
Adding new file types to permitted uploadsTo add a new extension to the list of allowed upload types, add a line like the following to a local customization file:$UploadExts['ext'] = 'content-type';
dxf ' extension with a Content-Type of 'image/x-dxf ', place the line
$UploadExts['dxf'] = 'image/x-dxf';
$UploadExts = array( 'gif' => 'image/gif', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'png' => 'image/png', 'xxx' => 'yyyy/zzz' ) Other file size limitsThere are other factors involved that affect upload file sizes. In Apache 2.0, there is a LimitRequestBody directive that controls the maximum size of anything that is posted (including file uploads). Apache has this defaulted to unlimited size. However, some Linux distributions (e.g., Red Hat Linux) limit postings to 512K so this may need to be changed or increased. (Normally these settings are in an httpd.conf configuration file or in a file in /etc/httpd/conf.d.) Problem noted on Red Hat 8.0/9.0 with Apache 2.0.x, the error "Requested content-length of 670955 is larger than the configured limit of 524288" was occurring under Apache and a "Page not found" would appear in the browser. Trying the above settings made no change with PHP, but on Red Hat 8.0/9.0 there is an additional PHP config file, /etc/httpd/conf.d/php.conf, and increasing the number on the line "LimitRequestBody 524288" solves the issue. PHP itself has two limits on file uploads (usually located in /etc/php.ini). The first is theupload_max_filesize parameter, which is set to 2M by default. The second is post_max_size , which is set to 6M by default.
With the variables in place--PmWiki's maximum file size, Apache's request-size limits, and the PHP file size parameters, the maximum uploaded file size will be the smallest of the three variables.
Password protecting uploaded filesSetting a read password for pages (and groups) will prevent an attached file from being seen or accessed through the page, but to prevent direct access to the file location (the uploads/ directory) one can do the following:
Other notes
file_uploads = On
$EnableDiag to 1 in config.php, and set ?action=phpinfo on a URL. The "file_uploads " variable must have a value of 1 (if it says "no value ", that means it's off).
Category: Administration
<< AuthUser | DocumentationIndex | Internationalizations >>
How do I disable uploading of a certain type of file? Here's an example of what to add to your local/config.php file to disable uploading of .zip files:$UploadExtSize['zip'] = 0; # Disallow uploading .zip files.
How do I attach uploads to individual pages or the entire site, instead of organizing them by wiki group? Use the$UploadPrefixFmt variable (see also the Cookbook:UploadGroups recipe).
$UploadPrefixFmt = '/$FullName'; # per-page
$UploadPrefixFmt = ''; # site-wide
For $UploadDirQuota - can you provide some units and numbers? Is the specification in bytes or bits? What is the number for 100K? 1 Meg? 1 Gig? 1 Terabyte? jb? Units are in bytes. |