PHP - Fatal Error Problem - Asked By Olusegun A. on 22-Nov-10 06:41 AM

I have the below code to add a vehicle detail to my website;

<?php
if(isset($_POST[Submit])){
$type=mysql_escape_string($_POST[type]);
$model=mysql_escape_string($_POST[model]);
$year=mysql_escape_string($_POST[year]);
$body=mysql_escape_string($_POST[body]);
$transition=mysql_escape_string($_POST[transition]);
$fuel=mysql_escape_string($_POST[fuel]);
$drive=mysql_escape_string($_POST[drive]);
$condition=mysql_escape_string($_POST[condition]);
$ecolour=mysql_escape_string($_POST[ecolour]);
$icolour=mysql_escape_string($_POST[icolour]);
$engine=mysql_escape_string($_POST[engine]);
$mile=mysql_escape_string($_POST[mile]);
$price=mysql_escape_string($_POST[price]);
$detail=addslashes($_POST[detail]);
$code=$_POST[code];
$date=date("d M y", time());

if($type=="")
{$error=$error."<span class='style2'>Select the Vehicle Make.</span><br>";
$bad="bad";}
if($model=="")
{$error=$error."<span class='style2'>Enter the Vehicle Model.</span><br>";
$bad="bad";}
if($body=="")
{$error=$error."<span class='style2'>Select the Vehicle body type.</span><br>";
$bad="bad";}
if($transition=="")
{$error=$error."<span class='style2'>Select the Vehicle transition type.</span><br>";
$bad="bad";}
if($fuel=="")
{$error=$error."<span class='style2'>Select the Vehicle fuel type.</span><br>";
$bad="bad";}
if($condition=="")
{$error=$error."<span class='style2'>Select the Vehicle condition.</span><br>";
$bad="bad";}
if($detail=="")
{$error=$error."<span class='style2'>Enter the Vehicle detail.</span><br>";
$bad="bad";}
if($code=="")
{$error=$error."<span class='style2'>Enter the security code.</span><br>";
$bad="bad";}
if($bad=="bad")
echo $error;
elseif(eregi('[^][0-9]' , $price))
echo "<span class='style2'>Enter only numbers in the Price space.</span><br>";
elseif(md5($_POST['code']) != $_SESSION['key'])
echo "<span class='style2'>You've entered wrong Security Code.</span><br>";
elseif($_FILES["file"]["name"]=="")
echo"<span class='style2'>Upload the main picture for this Vehicle.";
else{
$real_name = ($_FILES["file"]["name"]);
$filename = basename($_FILES['file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (!(($ext == "jpg") || ($ext == "png") || ($ext == "gif") || ($ext == "jpeg") || ($ext == "JPG"))) {
echo "<span class='style2'>The Picture format is not supported, upload a supported format.</span><br>";}
else{

$originalImage = $_FILES['file']['tmp_name'];
if ($ext == "gif")
$src = imagecreatefromgif($originalImage);
elseif ($ext == "png")
$src = imagecreatefrompng($originalImage);
elseif ($ext == "jpeg")
$src = imagecreatefromjpeg($originalImage);
else $src = imagecreatefromjpeg($originalImage);
list($width,$height) = getimagesize($originalImage);
$ratio = $width/$height;

if ($width > $height)
{if ($width > 500)
{$new_height = 500 / $ratio;
$new_width = 500;}
else
{$new_height = $height;
$new_width = $width;}}
else
{if ($height > 500)
{$new_width = 500 * $ratio;
$new_height = 500;}
else
{$new_height = $height;
$new_width = $width;}}

$rand_num1=rand(00000000000,99999999999);
$rand_num2=rand(00000000000,99999999999);
$rand_num3=rand(00000000000,99999999999);
$name = $rand_num1.$rand_num2.$rand_num3.$real_name;
$target = "../pictures/".$name;
$tmp = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($tmp,$src,0,0,0,0,$new_width,$new_height,$width,$height);
imagejpeg($tmp,$target,100);
if (file_exists($name))
echo "<span class='style3'>Please reupload the Picture.</span>";

else{

if($_FILES["file"]["name"] =="")
$path = "";
else $path = $target;

$vec=rand(00000,99999);
$check_vec=mysql_query("SELECT vec_id FROM vehicles WHERE vec_id='$vec'");
if(mysql_num_rows($check_vec)!=0)
echo "<span class='style2'>Kindly resubmit this Vehicle.</span><br>";
else{

$insertpic=mysql_query("INSERT INTO vecpictures(vec_id, vecimg, name, add_d, add_t, admin) VALUES('$vec', '$path', 'Main Picture', '$date', CURTIME(), '$admin_id')");
$insertit=mysql_query("INSERT INTO vehicles(vec_id, which, kind, odun, body, trans, fuel, drive, cond, ecolour, icolour, engine, mile, detail, vecimg, price, add_d, add_t, admin) VALUES('$vec', '$type', '$model', '$year', '$body', '$transition', '$fuel', '$drive', '$condition', '$ecolour', '$icolour', '$engine', '$mile', '$detail', '$path', '$price', '$date', CURTIME(), '$admin_id')");

if(!$insertpic) echo "<span class='style2'>Main Picture is not inserted.</span><br>".mysql_error();
elseif(!$insertit) echo "<span class='style2'>The Vehicle is not added, retry.</span><br>";
else{
$_SESSION[status]=ADDED;
header("location:vehicle_status.php?status=$_SESSION[status]");

}}}}}}
?>
nce i click on Submit button i receive an error message as below

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 14592 bytes) in C:\xampp\htdocs\tgal\admin\add_vehicle.php on line 136

and the code on line 137 is
$src = imagecreatefromjpeg($originalImage);

pls what's the way out
sinson p replied to Olusegun A. on 29-Nov-10 04:08 AM
there is in your web config file you have to change the maximum upload size,,otherwise you cannot upload a large image..
you can take it from localhost..
give more size for the upload limit..