Summary: Generates notifications also on upload events
Version: 0.1
Prerequisites: pmwiki 2.1.7 or higher; $EnableNotify = 1;
Status: quick hack
Maintainer: ThomasP
Categories: Uploads

Questions answered by this recipe

This section is optional; use it to indicate the types of questions (if any) this recipe is intended to answer.


This is a quick hack to trigger a mail notification every time an upload has taken place (successfully). The notification is channeled via the standard notify mechanism, so the options of that apply. This recipe introduces a further format variable $NotifyUploadItemFmt with which the appearance of the upload notification can be specified.


Below is the code of the current version, possibly amended/modified to add features / fix bugs. If you would like to contribute, please add your change and write a short summary below. If you want to download a stable version, rather use one of the "official" releases above.

<?php if (!defined('PmWiki')) exit();

// This is a quick hack to enable notifications on (successfull)
// uploads. It was tested under pmwiki 2.1.11 (Aug 2006),
// with SecureAtachments and UploadVersioning enabled.
// Note: this solution may not work properly in future versions
// of pmwiki if the interfaces of the notify functions change.
// Installation: copy this file into your cookbook dir and add
// the common include_once('cookbook/notifyOnUploads.php'); to
// your local/config.php.
// Ver 0.1, Aug 2006, ThomasP

// Tap (smoothly!) into the HandleUpload control flow: first save 
// the original HandleUpload function ...
SDV($HandleActions['upload'], 'HandleUpload');
$NOUdefaultHandleUploadFunc = $HandleActions['upload'];
// ... then set my new function
$HandleActions['upload'] = 'HandleUploadWithNoties';

// Have a custom NotifyItem format:
  ' * {$FullName} . . . $PostTime by {$LastModifiedBy} (uploaded/updated $Upfilename)');

function HandleUploadWithNoties($pagename, $auth = 'upload') {
  global $IsPagePosted, $NotifyItemFmt, $NotifyUploadItemFmt, 

  // first call original handler:
  $NOUdefaultHandleUploadFunc($pagename, $auth);
  // now check if we were successful:
  if (@$_REQUEST['upresult'] == 'success') {
    // save original IsPagePosted value and NotifyItem format:
    $NOUisPagePostedSaved = $IsPagePosted;
    $NOUnotifyItemFmtSaved = $NotifyItemFmt;
    // set them to values such that everything goes through as we want
    // (triggers a new notify item in the format specifed above):
    $IsPagePosted = true;
    $NotifyItemFmt = $NotifyUploadItemFmt;
    // dont forget to replace some $variables in Fmt: (a kind of pre FmtPageName)
    $NotifyItemFmt = str_replace('$Upfilename', $_REQUEST['uprname'], $NotifyItemFmt);
    // shoot the bullet:
    NotifyUpdate($pagename, getcwd());
    // restore original isPagePost value:
    $IsPagePosted = $NOUisPagePostedSaved;
    $NotifyItemFmt = $NOUnotifyItemFmtSaved;


For easy contribution/bug fixing, I have included the code as wiki text below. If you would like to contribute, go ahead.

Release Notes

  • Currently there exists one version, tested with pmwiki 2.1.11. It should work from pmwiki 2.1.7 (2006-05-31) onwards.
  • Corrected error in the comments. ThomasP August 14, 2006, at 04:48 PM
  • notifyOnUpload.phpΔ (ver0.1, 2006-08-14)

See Also

  • This recipe is a solution for 00785.
  • RecentUploadsLog -- a recipe to list uploaded files in RecentChanges -like pages.




See Discussion at NotifyOnUpload-Talk?

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.