<?php 
	//(c) 2002 by alphalogic
    include_once("../../mainfile.php");
    include_once(XOOPS_ROOT_PATH.'/modules/newbb_plus/config.php');

    $sql = "SELECT * FROM ".$bbTable['posts']." WHERE post_id=$attachid";
		if (!$result = $db->query($sql)) {
			die(_MD_DBERROR);
	}
	while ($o_attach = $db->fetch_object($result)) {
		if ($o_attach->attachment && $o_attach->attachment!='') {
			$attachment_csv = explode("|",$o_attach->attachment);
		} ELSE {
			die(_MD_NO_SUCH_FILE);
		}
	}
	if (!$attachment_csv && $attachment_csv=='') {
		die(_MD_NO_SUCH_FILE);
	}
	if(!file_exists($bbPath['path'].'cache/attachments/'.$attachment_csv[1])) {
		die(_MD_NO_SUCH_FILE);
	}
	$attachment_csv[3]++;
	$attachment_info = $attachment_csv[0].'|'.$attachment_csv[1].'|'.$attachment_csv[2].'|'.$attachment_csv[3];
	$sql = "UPDATE ".$bbTable['posts']." SET attachment= '$attachment_info' WHERE post_id=$attachid";
		if (!$result = $db->query($sql)) {
			die(_MD_DBERROR);
	}
	header("Content-type: $attachment_csv[2]");
	header("Content-Disposition: attachment; filename=$attachment_csv[0]");
	readfile($bbPath['path'].'cache/attachments/'.$attachment_csv[1]);
?>
 
