[pmwiki-users] From inside of config.php I need a good way to get the physical upload directory path (full path), or good way to create an attachment automatically.

Petko Yotov 5ko at 5ko.fr
Sat Apr 29 11:25:46 CDT 2017


> From inside of config.php I need a good way to get
> the physical upload directory path (full path),
> or good way to create an attachment automatically.

Here is a function in config.php that will be launched after all 
required scripts have been loaded:

   $PostConfig['CheckOrCreateUpload'] = 200;
   function CheckOrCreateUpload($pagename) {
     global $UploadFileFmt;

     $upname = "MyFile.txt";   # name of the uploaded file

     $pn = "Main.WiniSandbox"; # attached to specific page - OR -
     # $pn = $pagename;        # attached to current group/page

     $upname = MakeUploadName($pagename, $upname); # standard characters
     $filepath = FmtPageName("$UploadFileFmt/$upname", $pagename);

     if (!file_exists($filepath)) {
       file_put_contents($filepath, "Created ".strftime("%c"));
     }
   }

The function will look for an uploaded file with a specific name, 
attached to a specific page (or group, respecting your configuration). 
If such a file does not exist, it will be created.

The function is added to $PostConfig in order to let all configuration, 
farm, local, group, page, to be loaded, then the upload.php script to be 
loaded in the correct order (after prefs and forms) to include all 
functions, and before any PmWiki action (edit, browse, diff, 
download...) is processed.

Petko



More information about the pmwiki-users mailing list