UploadExtended

<< | Cookbook-V1 | >>

Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.


Attach:file.ext!!!Goal Δ

The goal of this module is to extend the upload functionality in the following ways:

  • Allow paths to be used together with the upload-related directives Attach: and [[$Attachlist]].
  • Allow international characters in filenames and paths.
  • Introduce a new directive, [[Attachlist:]], that only lists uploaded files in a specific group or directory.

Structure of upload directory

The standard structure of the upload area is as follows:

	uploads/
	|-- Group1/
	|   `-- aFile.txt
	|-- Group2/
	...

where the root directory of the upload area is set by the variable $UploadDir (it is uploads/ by default). Files that are attached to a PmWiki/WikiGroup are stored in a directory with the same name as the group, e.g. aFile.txt in the example above has been attached to Group1.

This module allows you to upload files to subdirectories, as well as store files directly in uploads/. The structure could look like this:

	uploads/
	|-- at-top-level.txt
	|-- Group1/
	|   |-- aFile.txt
	|   `-- dir1/
	|	`-- dir2/
	|-- Group2/
	|   `-- dir1/
	...

Solution

The solution has been implemented as a replacement for the original upload module, upload.php. It introduces the following modified or new directives:

Attach:...Now supports subdirectories and relative paths.
[[$Attachlist]]Now also lists contents of subdirectories.
[[Attachlist:]]New directive, lists a specified directory.
[[$Attachlist:]]New directive, same as [[Attachlist:]]

The development of this directive takes place at http://www.lyx.org/~chr/attachlist/pmwiki.php?pagename=Main.HomePage, and the very latest (development) version can be found at http://www.lyx.org/~chr/demo/pmwiki.php?pagename=Upload.Installation.

Paths

From a safety aspect, it is critical that this module does not allow users to access files or directories outside the upload area. For that reason, the code separately checks that a path does not contain '/../'. After that check has been made, the path is interpreted in the following manner:

  • The path '/' refers to the root directory, i.e. to $UploadDir.
  • A path not beginning with '/' is prepended with '/$Group/'.
    For example, dir is interpreted as $UploadDir/$Group/dir/.
    • Consequently, the empty path is interpreted as $UploadDir/$Group/.

Compability

This module used to require PmWiki 0.5.27 or later, but has been updated to work with 0.6.7. It is therefore unknown if it still works with 0.5.27 or later. The original requirement for 0.5.27 was based on Keep() so it is possible to have it working with versions in between 0.5.27 and 0.6.7.

See Also

These links cover the old functionality; please familiarize yourself with at least the page uploads first.

  • Uploads
  • PmWiki/UploadsAdmin
  • PmWiki/SpecialMarkups
  • Cookbook.PreventUploadOverwrites
  • Cookbook.UploadGroups

Installation

  1. Copy the new file Attach:upload.php.txt to local/upload.php
  2. Add these lines – or equivalent lines – to your local configuration file:
    $EnableUpload = 0;
    include_once('local/upload.php');
    $DefaultPasswords[upload] = crypt("mysecret");

Warning: This module maybe disable local control of uploading files, since it is possible to upload (or list) files to any group from any page.

Examples of using Attach:

Here are some examples to illustrate the new use of Attach::

Attach statement
 

Equivalent file path
(relative to $UploadDir)

 Attach:aFile.txt
 /$Group/aFile.txt
 Attach:subDirectory/aFileInSubdirectory.txt
 /$Group/subDirectory/aFileInSubdirectory.txt
 Attach:/at-top-level.txt
 /at-top-level.txt
 Attach:../at-top-level.txt
 /at-top-level.txt
 Attach:/Upload/aFile.txt
 /Upload/aFile.txt
 Attach:/AnotherGroup/aFileInAnotherGroup.txt
 /AnotherGroup/aFileInAnotherGroup.txt
 Attach:../AnotherGroup/aFileInAnotherGroup.txt
 /AnotherGroup/aFile.txt

Examples of using [[attach:]]

You can now use e.g.

	[[attach:aFile.txt]]

instead of Attach:aFile.txt. The difference is that the former allows you to have spaces in the filename, and is rendered without the text Attach:

Examples of using [[Attachlist:]]

Here are some examples to illustrate using the new directive [[Attachlist:]].

Source code

Directory listed (incl. any subdirectories)

 Attachlist:?

/$Group/

 Attachlist:subDirectory?

/$Group/subDirectory.

 AnotherGroup?

attachements to the group AnotherGroup.

You can use [[attachlist:]] instead of [[Attachlist:]]

Syntax

Below is a description of the syntax of the upload directives. It uses an extended BNF, see syntax notation? for a description of the extended BNF that is used.

    attach-statement ::= ( Attach: upload-path upload-name ) |
		         ( attach: upload-path upload-name1 ? )
    attachlist       ::= ( Attachlist: upload-path [+ws attachlist-sort *ws] ? ) |
			 ( attachlist: upload-path [+ws attachlist-sort *ws] ? )
    attachlist-old   ::= [[$Attachlist [+ws attachlist-sort *ws] ]]
    attachlist-alt   ::= [[$Attachlist: upload-path [+ws attachlist-sort *ws] ]]


    upload-path              ::= ?/ *( +upload-char /)
	upload-char          ::= upload-char-allowed | ~upload-char-disallowed
    	upload-char-allowed  ::= . | + | - | _
    	upload-char-disallowed ::= punct | cntrl | ws

    upload-name  ::= +upload-char

    upload-name1 ::= +( upload-char | ws )

Note that upload-path may be empty and that upload-char is any character in upload-allowed-punct, or any character not in upload-char-disallowed. The syntax of the optional argument attachlist-sort is as follows:

    attachlist-sort ::= attachlist-sort-by '=' attachlist-sort-order

    attachlist-sort-by ::= attachlist-sort-by-name |
			   attachlist-sort-by-size |
			   attachlist-sort-by-modification-time

	attachlist-sort-by-name   ::=  n | N
	attachlist-sort-by-size   ::=  s | S
	attachlist-sort-by-modification-time  ::=  m | M

    attachlist-sort-order ::= attachlist-ascending | attachlist-descending

	attachlist-ascending  ::= a | A
	attachlist-descending ::= d | D

History

2004-01-31
This page was created.
2004-03-05
Updated this page and uploaded version for 0.6.7
2004-05-11
Added [[attach:]] and [[attachlist:]] -- essentially as synomyms, but spaces now work in the filename thanks to Wayne.

Comments & Bugs

Suggestions

  • Add argument that prevents subdirectories from being listed, e.g. -l for locally, or do it the other way around: require -R in order to recursively list subdirectories. -- Christian
  • Allow people to use only parts of the functionality -- Christian
For instance, use separate enabling for the following functions:
  • Enabling international characters — enabled by default and it can be disabled (today actually) by redefining the variable $UploadCharPattern as follows:
  $UploadCharPattern = "[[:alnum:].+:_-]";
  • Enabling subdirectories — enabled by default and it can be disabled by adding the following line:
  $EnableUploadSubdirs = 0;
  • Enabling access across different groups — disabled by default and it can be enabled by the following line:
  $EnableUploadAcrossGroups = 1;
  • Add the ability to specify a file pattern for the @@[[Attachlist:]]@@-directive, by e.g. extending the syntax like this:
	attachlist       ::= [[Attachlist:
			     upload-path upload-file-filter  [+ws attachlist-sort *ws]
			 ]]
	upload-file-filter ::= *(upload-char | * | ?)
so an example would be: [[Attachlist:somDir/*.txt]] --Christian
  • Come up with a better name for the basic token than Attachlist --Christian. Adding some suggestions:
action=browsedir and BrowseDir: — ideas for the future

I'd like to do something like this:

	[[attachlist:someDir/ --non-recursive --browsedir]]

where subdirectories should show up as links, which when you click on them automatically lets you browse the directory you clicked on. One way of doing that is to implement a 'action=browsedir' but I want to remember which page the user came from so that he can return to it.

Anyway, this is for the future... I'm pretty busy right now since I've just started on a new job. /Christian PS. If I introdce an 'action=browsedir', I should probably also introduce a directive '<#>?' or 'BrowseDir:someDir/' which produces a link that when you click on it moves you to the browsing mode.

Extensions/modifications

Contributors

Copyright

Probably GPL, since this is based on the original upload.php pmwiki-2.3.32 -- Last modified by {{}}?

from IP: 85.171.160.186 ip should be disabled by default for security reasons