Location: PHPKode > scripts > OekakiPoteto > oekakipoteto/paintbbsget.php
<?
//Animation code by Marcello (http://www.cellosoft.com). Modified by RanmaGuy. Used with permission. This file is not to be used with any other script other than OekakiPoteto.
	include('config.php');
	include('dbconn.php');

	$buffer = $HTTP_RAW_POST_DATA;
	$data_type='image';
	$params = array('sid'=>$_GET[sid],'time'=>$_GET[time]);
	$vars = array ('sid'=>1,'time'=>1,'uid'=>1,'width'=>1,'height'=>1);
	
	function print_error($msg) {
		header("Content-type: text/plain\n\n");
		print "error\n";
		print "$msg\n";
		exit;
	}
	function print_ok() {
		print "Content-type: text/plain\n\n";
		print "ok";
		exit;
	}

	if (substr($buffer,0,1) == 'P') {
		$image[h_length] = substr($buffer, 1, 8);
		$image[h_length] = preg_replace('/^0*/','',$image[h_length]);
		$image[h_data]   = substr($buffer, 9, $image[h_length]);

		$a = explode(';', $image[h_data]);
		for ($i=count($a);--$i>=0;) {
		    $b = split('=', $a[$i]);
		    if ($vars[$b[0]]) $params[$b[0]]=$b[1];
		}
	}
	

	// Check for excess data
	if ($HTTP_SERVER_VARS[CONTENT_LENGTH] > $anisize) {
		print_error("Excess data! (over ".$anisize." bytes)");
	}


	// PaintBBS data
	if (substr($buffer,0,1) == 'P') {
		$image[o_length] = substr($buffer, $image[h_length] + 9, 8);
		$image[o_length] = preg_replace('/^0*/','',$image[o_length]);
		$image[o_data]   = substr($buffer, $image[h_length] + 19, $image[o_length]);

		$image[t_length] = substr($buffer, $image[h_length] + $image[o_length] + 19, 8);
		$image[t_length] = preg_replace('/^0*/','',$image[t_length]);
		$image[t_data]   = substr($buffer, $image[h_length] + $image[o_length] + 27, $image[t_length]);

		$image[t2_length] = substr($buffer, $image[h_length] + $image[o_length] + $image[t_length] + 27, 8);
		$image[t2_length] = preg_replace('/^0*/','',$image[t2_length]);
		$image[t2_data]   = substr($buffer, $image[h_length] + $image[o_length] + $image[t_length] + 35, $image[t2_length]);
		
		if ($image[t_data]) $data_type='imageplus';
	}
	
			$result = mysql_query("UPDATE ".$OekakiPoteto_Prefix."oekakimisc set miscvalue=miscvalue+1 where miscname='piccount'");
			$result = mysql_query("SELECT miscname, miscvalue FROM ".$OekakiPoteto_Prefix."oekakimisc where miscname='piccount'");
			$row = mysql_fetch_array($result);
			$resno = $row[miscvalue];

			//check if the picture is archived or not before saving
			$awrite = "false";
			while($awrite == "false"){
				$result = mysql_query("SELECT * FROM ".$OekakiPoteto_Prefix."oekakidta WHERE PIC_ID=".$resno);
				$row = mysql_fetch_array($result);
				if($row[archive] == "1"){
					//go to the next number
			$result = mysql_query("UPDATE ".$OekakiPoteto_Prefix."oekakimisc set miscvalue=miscvalue+1 where miscname='piccount'");
			$result = mysql_query("SELECT miscname, miscvalue FROM ".$OekakiPoteto_Prefix."oekakimisc where miscname='piccount'");
			$row = mysql_fetch_array($result);
			$resno = $row[miscvalue];
 	 			} else {
					$awrite = "true";
				}
			}

	if($mode == "picedit"){
		$image_filenamejpg = $OPpics.'/'.$edit.".jpg";
		$image_filename = $OPpics.'/'.$edit.".png";
		$anim_filename = $OPpics.'/'.$edit.".pch";
		$edittime2 = time() - $edittimes;
		$result2 = mysql_query("UPDATE ".$OekakiPoteto_Prefix."oekakidta SET edittime=(edittime + $edittime2) WHERE PIC_ID='$edit'");
		mysql_close();
		setcookie("edittime","",time() - 1209600);


	} else {			
		$image_filenamejpg = $OPpics.'/'.$resno.".jpg";
		$image_filename = $OPpics.'/'.$resno.".png";
		$anim_filename = $OPpics.'/'.$resno.".pch";
		$result = mysql_query("DELETE from ".$OekakiPoteto_Prefix."oekakicmt where PIC_ID='$resno'");
		$result = mysql_query("DELETE from ".$OekakiPoteto_Prefix."oekakidta where PIC_ID='$resno'");
		$thetime = time() - $edittimes;
		//insert the picture into the database
			$inserted = "false";
			while($inserted == "false"){
				$result = mysql_query("INSERT into ".$OekakiPoteto_Prefix."oekakidta SET usrname='$username',hostname='$hostname', postdate=NOW(), PIC_ID='$resno', IP='$REMOTE_ADDR', animation='1', edittime='$thetime'");

				$result = mysql_query("SELECT count(*) as rowcount FROM ".$OekakiPoteto_Prefix."oekakidta WHERE PIC_ID='$resno'");
				$r_rows = mysql_fetch_array($result);
				if($r_rows[rowcount] == 1){
					$inserted = "true";
				}
			}
		mysql_close();
	}

	unlink($image_filename);
	if ($fp = fopen($image_filename,'wb')) {
		// Write main file
		fwrite($fp,$image[o_data]);
		fclose($fp);
		
		// Verify size matches applet parameters
		if ($params[width]&&$params[height]&&($params[width]!=$info[0]||$params[height]!=$info[1]))
			print_error("Stored image size doesn't match!\n({$info[0]}x{$info[1]} != {$params[width]}x{$params[height]})");

		if($jpgcompression == "yes"){

			//convert to JPEG

			$img = imagecreatefrompng($image_filename);

			imagejpeg($img,$image_filenamejpg, $jpgcompressqual);

		}

		if ($image[t_data]) {
			// Write animation file (if exists)
			unlink($anim_filename);
			if ($fp = fopen($anim_filename,'wb')) {
				fwrite($fp,$image[t_data]);
				fclose($fp);
				print_ok();
			}
		} else {
			print_ok();
		}
		
	}
	mysql_close();
	print_error("Server error: Could not create image file.\nPlease try sending your image again.");
	
?>
Return current item: OekakiPoteto