[Pmwiki-users] How to prevent attachment replacement?

Patrick R. Michaud pmichaud at pobox.com
Thu Jul 10 11:54:00 CDT 2003


On Thu, Jul 10, 2003 at 12:21:23PM -0300, Fabio Reis Cecin wrote:
> 
> Hi! I've just noticed that uploaded files (Attach:*) can be replaced by
> uploading another file with the same name. How do I prevent this?

You can change $UploadVerifyFunction to be any verification function
desired.  By default it's "UploadVerifyBasic", but you can set it
to a different one, e.g., to see if the file already exists or not.  
Place the code at the bottom of this email in local.php and you
should get what you want.  I'll probably add it to the cookbook
a bit later also.

> Also, IMHO it would be a good idea to turn this behavior off by default,
> since you cannot "restore" an attachment.

I thought about this, but often what happens is that someone will upload
a document or gif, notice that they want to change something, and then
immediately replace the attachment with a new one. It's very frustrating
if they have to give it a new name (and possibly update a lot of links).
Plus, for a lot of PmWiki applications (e.g. web site maintenance)
the allow-replace policy makes much more sense.  So, I chose a default 
policy of allowing replacements because it seemed more in the spirit of 
wikis, with the idea that it could be easily turned off for specific 
applications.

I also thought about keeping "attachment versions", but that adds a lot more
software and management complexity and could eat up disk space pretty 
quickly.  However, upload.php is an optional module (not built into
pmwiki.php), so if someone wants to write a totally different implementation
that's certainly possible!  :-)

> I'm using a Pmwiki-0.4.x version.

I think the code below *should* work with pmwiki-0.4.x, as the upload 
feature really hasn't changed substantially since its initial release.

Pm

--------

Place the following in local.php, or put it in a separate file in 
local/ and include it:

<?php

function UploadVerifyNew($pagename,$uploadfile,$filepath) {
  if (file_exists($filepath)) return 'upresult=exists';
  return UploadVerifyBasic($pagename,$uploadfile,$filepath);
}

SDV($UploadResultMsgs['exists'],
  ': file already exists--use a different attachment name');
$UploadVerifyFunction = 'UploadVerifyNew';

?>





More information about the pmwiki-users mailing list