[ewiki] ewiki_binary() patch
- From: Andy Fundinger <andy@xxxxxxxxxxx>
- To: "'ewiki@xxxxxxxxxxxxx'" <ewiki@xxxxxxxxxxxxx>
- Date: Thu, 11 Mar 2004 12:01:02 -0500
My team member, Jeff added error logging for binary file errors. Also, I
would like to add a meta data field to cached images. The perm_liveuser
functions use this to set cached images to have different rights than
uploaded ones.
elseif ($do == "cache") {
#-- check for standard protocol names, to prevent us from serving
# evil requests for '/etc/passwd.jpeg' or '../.htaccess.gif'
if (preg_match('@^\w?(http|ftp|https|ftps|sftp)\w?://@', $id)) {
#-- generate local copy
$filename = tempnam(EWIKI_TMP, "ewiki.local.temp.");
if (($i = fopen($id, "rb")) && ($o = fopen($filename, "wb"))) {
while (!feof($i)) {
if($handle = fread($i, 65536)){
if(!fwrite($o, $handle)){
ewiki_log("ewiki_binary: error writing to $filename in
binary-cache", 0);
}
} else {
ewiki_log("ewiki_binary: error reading from $id in
binary-cache", 0);
}
}
if(!fclose($i)){
ewiki_log("ewiki_binary: error closing $id in
binary-cache", 1);
}
if(!fclose($o)){
ewiki_log("ewiki_binary: error closing $filename in
binary-cache",1);
}
$add_meta = array(
"Content-Location" => urlencode($id),
"Content-Disposition" => 'inline;
filename="'.urlencode(basename($id)).'"',
'PageType' => 'CachedImage'
);
$result = ewiki_binary_save_image($filename, $id, "RETURN",
$add_meta);
}
}
also, can we add a set of binary_handlers? These would run in
binary_save_image() as follows:
#-- write if not exist
$exists = ewiki_database("FIND", array($id));
if (! $exists[$id] ) {
#-- handlers
if ($pf_a = @$ewiki_plugins['binary_handler']) {
ksort($pf_a);
foreach ($pf_a as $pf) {
$pf($id, $data, 'save');
}
}
$result = ewiki_database("WRITE", $data);
ewiki_log("saving of '$id': " . ($result ? "ok" : "error"));
- Follow-Ups:
- [ewiki] Re: ewiki_binary() patch, ewiki_control_links() refactor
- From: Mario Salzer
- [ewiki] Re: ewiki_binary() patch
- From: Andy Fundinger
Other related posts:
- » [ewiki] ewiki_binary() patch
- » [ewiki] Re: ewiki_binary() patch
- [ewiki] Re: ewiki_binary() patch, ewiki_control_links() refactor
- From: Mario Salzer
- [ewiki] Re: ewiki_binary() patch
- From: Andy Fundinger