[pmwiki-users] Image Attachments and sub-directories
Ben Wilson
dausha at gmail.com
Sat May 20 11:38:23 CDT 2006
On 5/20/06, DaveG <pmwiki at solidgone.com> wrote:
> I have a page in a group MyGroup.PageName. This particular page has a
> lot of images and I'd like to store them in their own sub-directory.
> Thus the images are in uploads/MyGroup/subdir.
. . . [snip] . . .
>
> What syntax should I use?
You may want to influence $UploadPrefixFmt. Its default is '/$Group',
and you want something like '/$Group/images'. However, that would
affect all uploads. So, you need a way to tell it when to affect this
variable, and when to remain silent.
Perhaps interject a little subroutine? What I've coded below is a
rough draft. What I'm doing is interjecting a checksum routine before
the actual uploading of the page. I'm using the fact that PmWiki
already tracks which extensions are images via a fairly universal
standard--so I won't hardcode.
So, the routine extracts the extension, checks against the known image
formats, then appends the "image" subdirectory to UploadPrefixFmt when
we have a recognized image format.
$HandleActions['postupload'] = 'PrefixImages'; #Defaults to
HandlePostUpload();
function PrefixImages($p, $a='upload') {
global $UploadExts, $UploadPrefixFmt
$upname = $_REQUEST['upname'];
if ($upname=='') {
$uploadfile = $_FILES['uploadfile'];
$upname=$uploadfile['name']; }
$ext = split('.', $upname);
$xtype = split('/', $UploadExts[$ext[-1]]);
if ($xtype[0] == 'image') $UploadPrefixFmt .= '/images';
HandlePostUpload($p, $a); } # Returning the fish to the stream.
--
Ben Wilson
" Mundus vult decipi, ergo decipiatur"
More information about the pmwiki-users
mailing list