PmWiki has a feature script called
Some notes about security
1. Keep in mind that letting users (anonymously!) upload files to your web server does entail some amount of risk. The
2. By default, authorized users are able to overwrite files that have already been uploaded, without the possibility of restoring the previous version of the file. If you want to disallow users from being able to overwrite files that have already been uploaded, add the following line to config.php:
$EnableUploadOverwrite = 0;
The upload.php script is automatically included from stdconfig.php if the
Thus, a basic config.php for uploads might look like:
For the upload feature to work properly, the directory given by $UploadDir must be writable by the web server process, and it must be in a location that is accessible to the web somewhere (e.g., in a subdirectory of public_html). The WikiAdministrator can either create the upload directory manually, or PmWiki will attempt to create the directory when it is run with the upload feature enabled. To have PmWiki automatically create the directory, (1) change the permissions of the parent directory to 2777, (2) execute PmWiki with the upload feature enabled, (3) verify that the upload directory is created, and (4) restore the parent directory's permissions to their previous value (755 is generally "safe").
For example, if the upload directory is going to be "/home/john/public_html/uploads", one would do "
Once 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 "
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.
Restricting uploaded files
The upload script performs a number of verifications on an uploaded file before storing it in the upload directory. The basic verifications are described below.
filenames - the name for the uploaded file can contain only letters, digits, underscores, hyphens, spaces, and periods, and the name must begin and end with a letter or digit.
file extension - only files with approved extensions such as ".gif", ".jpg", ".doc", etc. are allowed to be uploaded to the web server. This is vitally important for server security, since the web server might attempt to execute or specially process files with extensions like ".php", ".cgi", etc.
file size - By default all uploads are limited to 50K bytes, as specified by the $UploadMaxSize variable. Thus, to limit all uploads to 100K, simply specify a new value for $UploadMaxSize in config.php:
$UploadMaxSize = 100000;
However, maximum file sizes can also be specified for each type of file uploaded. Thus, an administrator can restrict ".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
Setting an entry to zero disables file uploads of that type altogether:
$UploadExtSize['zip'] = 0; # disallow .zip files
There 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.)
PHP itself has two limits on file uploads. The first is the upload_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.
TODO: finish documenting UploadsAdmin
file_uploads = On
Note that if you change this value, httpd must generally be restarted. Another way to check if uploads are allowed by the server is to set $EnableDiag to 1 in config.php, and set ?action=phpinfo on a URL. The "