Extension:Painting/Code/savepainting.php

<?php

$bmp = stripslashes($_POST['bitmap']); // DISTANT ONLY $basicsizesent = strlen($_POST['bitmap']); //$bmp = $_POST['bitmap']; // LOCAL ONLY

//$bmp = urldecode($_POST['bitmap']); // test

$sizesent = strlen($bmp); //$png = utf8_decode($bmp); $png = $bmp; $size = strlen($png); $user = utf8_decode($_POST['user']); $title = utf8_decode($_POST['title']); $time = utf8_decode($_POST['time']); $pagetitle = utf8_decode($_POST['pagetitle']); $comment = utf8_decode($_POST['comment']); $originsize = utf8_decode($_POST['originsize']); $env = utf8_decode($_POST['env']);

$title = str_replace('/','_',$title); $title = str_replace('.','_',$title); $ip = $HTTP_SERVER_VARS["REMOTE_ADDR"]; $dns = gethostbyaddr($ip); $date = date ("D d M y H:i");

$handle = fopen ("paintinglog.txt", "a"); fputs($handle,"$date\t$user\t$ip\t$dns\t$title\t$size\t$originsize\t$time\t$pagetitle\t$i\t$comment\t$env\n"); fclose($handle);

echo "Decoding image : ($originsize ->) $basicsizesent -> $sizesent -> $size bytes\n"; if ($size != $originsize) {	echo "FATAL ERROR : Java applet and PHP script bitmap sizes don't match. PLEASE TRY AGAIN."; } else {

$pix = fopen("paintings/".$title.".png","w"); fwrite($pix,$png); fclose($pix); $i = 0; if (file_exists("paintings/".$title.".txt")) { $txt = fopen("paintings/".$title.".txt","r"); if ($txt) {	while (!feof($txt)) {	$a = fgets($txt); if ($a != FALSE) $i++; }	fclose($txt); } }

$txt = fopen("paintings/".$title.".txt","a"); fputs($txt,"$i\t$user\t$pagetitle\t\t$date\t$size\t$time\t$comment\n"); fclose($txt);

$pix = fopen("paintings/".$title."-".$i.".png","w"); fwrite($pix,$png); fclose($pix); echo "Image $title-$i successfully saved at $date ($size bytes)"; } ?>