Location: PHPKode > projects > Chinese Project Forum > upload/attach.php
<?
error_reporting(7);
require("global.php");

$noheader=1;

if($id) {
	$attachinfo = &$conn->Execute("SELECT * FROM ".$prefix."_attachment WHERE id=$id");
	$attachinfo = $attachinfo->fields;
	$f=fopen("uploadfiles/$attachinfo[savefilename]","rb");
	$content=fread($f,filesize("uploadfiles/$attachinfo[savefilename]"));
	fclose($f);

	header("Cache-control: max-age=31536000");
	header("Expires: " . gmdate("D, d M Y H:i:s",time()+31536000) . "GMT");
	header("Last-Modified: " . gmdate("D, d M Y H:i:s",$attachinfo[time]) . "GMT");
	header("Content-disposition: filename=$attachinfo[originfilename]");
	header("Content-Length: ".strlen($content));
	$extension=getextension($attachinfo[originfilename]);
	if ($extension=="gif") {
		header("Content-type: image/gif");
	} elseif ($extension=="jpg" or $extension=="jpeg") {
		header("Content-type: image/pjpeg");
	} elseif ($extension=="png") {
		header("Content-type: image/png");
	} elseif ($extension=="zip") {
		header("Content-type: application/x-zip-compressed");
	} elseif ($extension=="txt" or $extension=="php" or $extension=="inc") {
		header("Content-type: text/plain");
	} else {
		header("Content-type: unknown/unknown");
	}
	echo $content;
	$conn->Execute("UPDATE ".$prefix."_attachment SET hits = hits + 1 WHERE id=$id");
}
?>
Return current item: Chinese Project Forum