Well I have a script that processes images and displays them as formatted signature-style pixels. It was working well a few weeks ago, and in fact it had never been malfunctioning in the past. The problem is, well, instead of actually showing the siggy image, it shows a server connection error like this:
[ATTACH]4727[/ATTACH]
I have absolutely no idea why it goes wrong like this. It all started after I upgraded my PHP version, I am currently using PHP 5.3.18 but this might have been there since the last upgrade to PHP 5.3.16. For this reason I wonder if it has anything to do with the new PHP version not supporting any of the old functions I am using in the script? Anyway I havent touched this script like in ages, theres a good chance. I've posted the entire code, can anyone of you please go through it and lemme know if there are any deprecated functions or functions that got modified significantly in new php releases? I am just totally clueless now...
<?php
include("functions/functions.php");
include("functions/functions_users.php");
include("functions/functions_adopts.php");
include("inc/lang.php");
//***************//
// START SCRIPT //
//***************//
// We need to grab an adoptable ID
$id = $_GET["id"];
// Check that ID exists and is valid
if(is_numeric($id)){
// The ID appears to be valid, so double check...
$row = $adopts->select("owned_adoptables", array(), "aid='{$id}'")->fetchObject();
if($row->aid == $id){
// The adoptable exists, so let's try and show the image
$usingimage = "no";
$image = getcurrentimage($id);
// Let's see if the server has support for GD or not
// Also to use fancy images the image must be a gif and fancy images must be enabled...
$usegd = grabanysetting("gdimages");
$imageinfo = @getimagesize($image);
$imagemime = $imageinfo["mime"]; // Mime type of the image file, should be a .gif file...
if(function_exists('imagegif') and $usegd == "yes" and $imagemime == "image/gif")
{
$usingimage = "yes"; //Turn the template system off
// BEGIN NEW CODE
list($width, $height, $row->type, $attr) = getimagesize($image); // The size of the original adoptable image
// Begin the fancy outputs...
// Lets create the new target image, with a size big enough for the text for the adoptable
$newheight = $height + 72;
if($newwidth < 250){
$newwidth = 250;
}
else{
$newwidth = $width;
}
$img_temp = imagecreatetruecolor($newwidth, $newheight);
$alphablending = true;
// Lets create the image and save its transparency
$img_old = @imagecreatefromgif($image);
imagealphablending($img_old, true);
imagesavealpha($img_old, true);
// Lets copy the old image into the new image with
// the given size
ImageCopyResampled(
$img_temp,
$img_old,
0, 0, 0, 0,
$width,
$height,
$width,
$height
);
$textheight = $width + 2;
$image = $img_temp;
$bgi = imagecreatetruecolor($newwidth, $newheight);
$color = imagecolorallocate($bgi, 51, 51, 51);
$str1 = "Name: ".$row->name;
$str2 = "Owner: ".$row->owner;
$str3 = "Click Here to Feed Me!";
$str4 = "More Adopts at:";
$str5 = "www.".constant("DOMAIN");
imagestring ($image, 12, 0, $textheight, $str1, $color);
imagestring ($image, 12, 0, $textheight + 13, $str2, $color);
imagestring ($image, 12, 0, $textheight + 26, $str3, $color);
imagestring ($image, 12, 0, $textheight + 42, $str4, $color);
imagestring ($image, 12, 0, $textheight + 55, $str5, $color);
$background = imagecolorallocate($image, 0, 0, 0);
ImageColorTransparent($image, $background);
header("Content-Type: image/GIF");
ImageGif ($image);
imagedestroy($image);
imagedestroy($img_temp);
imagedestroy($img_old);
imagedestroy($bgi);
}
else{
// We are going to try and get this image the old fashioned way...
// Define a list of allowed file extentions...
$extList = array();
$extList['gif'] = 'image/gif';
$extList['jpg'] = 'image/jpeg';
$extList['jpeg'] = 'image/jpeg';
$extList['png'] = 'image/png';
//Define the output file type
$contentType = 'Content-type: '.$extList[ $imageinfo['extension'] ];
if($imageinfo['extension'] =! "image/gif" and $imageinfo['extension'] =! "image/jpeg" and $imageinfo['extension'] =! "image/png"){
// The file type is NOT ALLOWED
die("Hacking Attempt!");
}
else{
// File type is allowed, so proceed
// Try and read the file in
$status = "";
header ($contentType);
$status = readfile($image);
if($status == "" or $status == "false" or $status == "FALSE"){
// Reading the file failed, so show an error...
header ("text/plain");
die("Readfile appears to be disabled on your host.");
}
}
}
}
else{
// Bogus ID
$article_title = $err_idnoexist;
$article_content = $err_idnoexist_text;
}
}
else{
// Bogus ID
$article_title = $err_idnoexist;
$article_content = $err_idnoexist_text;
}
?>
server error.png