Jump to content

[SOLVED] Issue with thumbnail script. Could be server related?


Solarpitch

Recommended Posts

Hi Guys,

 

I am currently using the below Ian Selby script to generate an thumbnail from an image and save it to the server. There is noting wrong with the script as I have tested it on different servers and use it on other sites, and it works fine.

 

However, on a new site I am developing the thumbnail it tries to copy is just a black image. Then gives me the message...

 

"Warning: imagecopyresampled(): 7 is not a valid Image resource"

 

My php has gd enabled also. I am not gonna post the thumbnail.inc.php file with the associated functions as I know this code already works.

 

Like I said I think its an issue with something else. Can anyone suggest anything thats work trying? I've been 3 days at this so I have to seek some help now. Thanks.

 


$imagedir = "property_images/";

$timest = time();
$image1 = $_FILES['image1']['tmp_name'];

	if($image1 != ""){
			$image1exists = 1; 
			$includesimage = '1';

		}

		if($image1exists == 1){

			$image1file = $imagedir.$timest."AA".basename($_FILES['image1']['name']);

		}


		if($image1exists == 1){

			$image1 = $imagedir.$timest."AA".basename($_FILES['image1']['name']);


		}


		if($image1exists == 1){

			$image1a = $imagedir."THUMB".$timest."AA".basename($_FILES['image1']['name']);

		}

		if($_FILES['image1']['tmp_name'] != ""){
		echo "hello";
			list($width, $height, $type, $attr) = getimagesize($_FILES['image1']['tmp_name']);
			move_uploaded_file($_FILES['image1']['tmp_name'], $image1file);

			if($width > $height){ $istaller = "0";}
			if($width < $height){ $istaller = "1";}
			if($width == $height){ $istaller = "2";}

				$thumb = new Thumbnail($image1file);

			if($istaller == "0"){
				$thumb->resize('0','160');
				$thumb->cropFromCenter('160');
				}elseif($istaller == "1"){
				$thumb->resize('160','0');
				$thumb->cropFromCenter('160');
			}else{
				$thumb->resize('160','160');
			}
			$thumb->save($image1a,100);
			if($height > "650"){
			$thumb2 = new Thumbnail($image1file);
				if($istaller == "0"){
					$thumb2->resize('0','650');
					$thumb2->cropFromCenter('650');
					}elseif($istaller == "1"){
					$thumb2->resize('650','0');
					$thumb2->cropFromCenter('650');
				}else{
					$thumb2->resize('650','650');
				}
				$thumb2->save($image1,100);
			}
		}

 

 

 

Just the imagecopyresampled() in thumbnail.inc.php

 


imagecopyresampled(
            $this->workingImage,
            $this->oldImage,
            0,
            0,
            $startX,
            $startY,
            $width,
            $height,
            $width,
            $height
	);

	$this->oldImage = $this->workingImage;
	$this->newImage = $this->workingImage;
	$this->currentDimensions['width'] = $width;
	$this->currentDimensions['height'] = $height;
}

Link to comment
Share on other sites

All permissions have been checked. The part quoted does work as it uploads the main image. The thumbnail seems to upload also, but it uploads as a black image.

 

The way the script works is it sets a black background and then copies the image over it, but it doesnt seem to be doing the copying part and fails at the function I listed for whatever reason. The same code works on other sites I done so I cant understand why I am having problems with this script.

Link to comment
Share on other sites

Hi,

 

I did'nt get a chance to gather any error's yesterday buy just in relation to what you about "problem is related to $image1file"

 

I use the exact same code and file permissions on 2 other sites and the thumbnail seems to upload fine. Could this problem even be related to the GD Library on this sites server... although I dont think so.

 

What kind of debugging code could I try?

 

I am not quite sure what the below message is saying but it must be the problem that is stopping the image copying to the thumbnail

 

"Warning: imagecopyresampled(): 7 is not a valid Image resource"

Link to comment
Share on other sites

Hi,

 

I inserted that code into the script and gave me this result...

 

bool(false) NULL END

 

 


		if($_FILES['image1']['tmp_name'] != ""){

			list($width, $height, $type, $attr) = getimagesize($_FILES['image1']['tmp_name']);
			$check = move_uploaded_file($_FILES['image1']['tmp_name'], $image1file);
			var_dump($check, $image1file);
			die("END");//

			if($width > $height){ $istaller = "0";}

Link to comment
Share on other sites

Problem with the upload

this line fails..

move_uploaded_file($_FILES['image1']['tmp_name'], $image1file);

reason..is this $image1file is not being set

 

add line (see comments)

<?php

	$image1 = $_FILES['image1']['tmp_name'];
//ADD
echo "Testing123:";
var_dump($_FILES);
	if($image1 != ""){
			$image1exists = 1; 
			$includesimage = '1';

		}

		if($image1exists == 1){

			$image1file = $imagedir.$timest."AA".basename($_FILES['image1']['name']);
			//ADD THIS
			echo "I am set:";
			var_dump($image1file);
		}
?>

Link to comment
Share on other sites

Hi,

 

I got a chance to insert that code there but I dont seem to be able to see the output from it as when the form is submitted with an image, it just reloads that page (as a blank page) and prints the address/ URL of the page along the top

 

This only happens when I include an image in the upload. I am thinking it could be to do with the way the header is set, but maybe not. I'll print the code again below to show you the lot...

 

 



<?php


session_start();

include('../params/params.php');
include_once('thumbnail.inc.php');


if(!isset($_SESSION['valid_admin']))
{
	header("Location:index.php");
}



$process = "";
$process = isset($_POST['process']) ? $_POST['process'] : '';

if ($process != "execute")
{
//not being submitted...
}
else
{	



$county=""; $location=""; $type=""; $price="";$bedrooms="";$sale_type="";$description="";$accomodation="";

 $county = $_POST['county'];
 $location = $_POST['location'];
 $type = $_POST['type'];

 $address = $_POST['address'];
 $price = $_POST['price'];
 $bedrooms = $_POST['bedrooms'];

 $sale_type = $_POST['sale_type'];
 $description = $_POST['description'];
 $features = $_POST['features'];

 $accomodation = $_POST['accomodation'];



if($county == ""){
		$countyerror = "Please select a county.";
		$error=1;
	}elseif($location == ""){
		$locationerror = "Please select a location.";
		$error=1;
	}elseif($type == ""){
		$typeerror = "Please select a property type.";
		$error=1;
	}elseif($address == ""){
		$addresserror = "Please enter an address for this property.";
		$error=1;
	}elseif($price == ""){
		$priceerror = "Please enter a price for this property.";
		$error=1;
	}elseif($description == ""){
		$descriptionerror = "Please enter a description for this property.";
		$error=1;
	}

	if($error == 1){
		//an error occured cant save...
	}else{


$imagedir = "property_images/";

	$timest = time();

	$image1 = $_FILES['image1']['tmp_name'];
                echo "Testing123:";
                var_dump($_FILES);


	    if($image1 != ""){
			$image1exists = 1; 
			$includesimage = '1';

		}


		$image1exists="";
		$image1a=""; 


		if($image1exists == 1){

			$image1file = $imagedir.$timest."AA".basename($_FILES['image1']['name']);
			//ADD THIS
			echo "I am set:";
			var_dump($image1file);
		}


		if($image1exists)
                         {
                             $image1 = $imagedir.$timest."AA".basename($_FILES['image1']['name']);
                         }


		if($image1exists)
                        {
                             $image1a = $imagedir."THUMB".$timest."AA".basename($_FILES['image1']['name']);
                        }



		if($_FILES['image1']['tmp_name'] != ""){

			list($width, $height, $type, $attr) = getimagesize($_FILES['image1']['tmp_name']);
			move_uploaded_file($_FILES['image1']['tmp_name'], $image1file);

			if($width > $height){ $istaller = "0";}
			if($width < $height){ $istaller = "1";}
			if($width == $height){ $istaller = "2";}


				$thumb = new Thumbnail($image1file);
			if($istaller == "0"){
				$thumb->resize('0','100');
				$thumb->cropFromCenter('100');
				}elseif($istaller == "1"){
				$thumb->resize('100','0');
				$thumb->cropFromCenter('100');
			}else{
				$thumb->resize('100','100');
			}
			$thumb->save($image1a,100);
			if($height > "650"){
			$thumb2 = new Thumbnail($image1file);
				if($istaller == "0"){
					$thumb2->resize('0','650');
					$thumb2->cropFromCenter('650');
					}elseif($istaller == "1"){
					$thumb2->resize('650','0');
					$thumb2->cropFromCenter('650');
				}else{
					$thumb2->resize('650','650');
				}
				$thumb2->save($image1,100);
			}
		}


$insertproperty="";
insertproperty($county, $location, $type, $address, $price, $bedrooms, $sale_type, $description, $features,  $accomodation, $image1, $image1a, $image2, $image3, $image4, $image5, $image6);

if($insertproperty == 0){
			echo $generalerror = "Error uplaoding files(s).";
		}else{
			echo $generalerror = "Files Uploaded.";
		}
	}

}


?>

Link to comment
Share on other sites

 

Hi,

 

I got a chance to run that script. I just printed out the full php script on the page below so you can see the lot. When I inserted you code in the script I got...

 


Testing123: 

array(6) { ["image1"]=>  array(5) { ["name"]=>  string(9) "house.jpg" ["type"]=>  string(10) "image/jpeg" ["tmp_name"]=>  string(14) 

"/tmp/phpJV1JUm" ["error"]=>  int(0) ["size"]=>  int(82082) } ["image2"]=>  array(5) { ["name"]=>  string(0) "" ["type"]=>  

string(0) "" ["tmp_name"]=>  string(0) "" ["error"]=>  int(4) ["size"]=>  int(0) } ["image3"]=>  array(5) { ["name"]=>  

string(0) "" ["type"]=>  string(0) "" ["tmp_name"]=>  string(0) "" ["error"]=>  int(4) ["size"]=>  int(0) } ["image4"]=>  

array(5) { ["name"]=>  string(0) "" ["type"]=>  string(0) "" ["tmp_name"]=>  string(0) "" ["error"]=>  int(4) ["size"]=>  

int(0) } ["image5"]=>  array(5) { ["name"]=>  string(0) "" ["type"]=>  string(0) "" ["tmp_name"]=>  string(0) "" ["error"]=>  

int(4) ["size"]=>  int(0) } ["image6"]=>  array(5) { ["name"]=>  string(0) "" ["type"]=>  string(0) "" ["tmp_name"]=>  

string(0) "" ["error"]=>  int(4) ["size"]=>  int(0) } } I am set:string(37) "property_images/1194103595AAhouse.jpg"

 

 

 

Full php page code...

 



<?php


session_start();

include('../params/params.php');
include_once('thumbnail.inc.php');


if(!isset($_SESSION['valid_admin']))
{
	header("Location:index.php");
}



$process = "";
$process = isset($_POST['process']) ? $_POST['process'] : '';

if ($process != "execute")
{
//not being submitted...
}
else
{	



$county=""; $location=""; $type=""; $price="";$bedrooms="";$sale_type="";$description="";$accomodation="";

 $county = $_POST['county'];
 $location = $_POST['location'];
 $type = $_POST['type'];

 $address = $_POST['address'];
 $price = $_POST['price'];
 $bedrooms = $_POST['bedrooms'];

 $sale_type = $_POST['sale_type'];
 $description = $_POST['description'];
 $features = $_POST['features'];

 $accomodation = $_POST['accomodation'];



if($county == ""){
		$countyerror = "Please select a county.";
		$error=1;
	}elseif($location == ""){
		$locationerror = "Please select a location.";
		$error=1;
	}elseif($type == ""){
		$typeerror = "Please select a property type.";
		$error=1;
	}elseif($address == ""){
		$addresserror = "Please enter an address for this property.";
		$error=1;
	}elseif($price == ""){
		$priceerror = "Please enter a price for this property.";
		$error=1;
	}elseif($description == ""){
		$descriptionerror = "Please enter a description for this property.";
		$error=1;
	}

	if($error == 1){
		//an error occured cant save...
	}else{


$imagedir = "property_images/";

	$timest = time();

	$image1 = $_FILES['image1']['tmp_name'];
                echo "Testing123:";
                var_dump($_FILES);


	    if($image1 != ""){
			$image1exists = 1; 
			$includesimage = '1';

		}


		$image1exists="";
		$image1a=""; 


		if($image1exists == 1){

			$image1file = $imagedir.$timest."AA".basename($_FILES['image1']['name']);
			//ADD THIS
			echo "I am set:";
			var_dump($image1file);
		}


		if($image1exists)
                         {
                             $image1 = $imagedir.$timest."AA".basename($_FILES['image1']['name']);
                         }


		if($image1exists)
                        {
                             $image1a = $imagedir."THUMB".$timest."AA".basename($_FILES['image1']['name']);
                        }



		if($_FILES['image1']['tmp_name'] != ""){

			list($width, $height, $type, $attr) = getimagesize($_FILES['image1']['tmp_name']);
			move_uploaded_file($_FILES['image1']['tmp_name'], $image1file);

			if($width > $height){ $istaller = "0";}
			if($width < $height){ $istaller = "1";}
			if($width == $height){ $istaller = "2";}


				$thumb = new Thumbnail($image1file);
			if($istaller == "0"){
				$thumb->resize('0','100');
				$thumb->cropFromCenter('100');
				}elseif($istaller == "1"){
				$thumb->resize('100','0');
				$thumb->cropFromCenter('100');
			}else{
				$thumb->resize('100','100');
			}
			$thumb->save($image1a,100);
			if($height > "650"){
			$thumb2 = new Thumbnail($image1file);
				if($istaller == "0"){
					$thumb2->resize('0','650');
					$thumb2->cropFromCenter('650');
					}elseif($istaller == "1"){
					$thumb2->resize('650','0');
					$thumb2->cropFromCenter('650');
				}else{
					$thumb2->resize('650','650');
				}
				$thumb2->save($image1,100);
			}
		}


$insertproperty="";
insertproperty($county, $location, $type, $address, $price, $bedrooms, $sale_type, $description, $features,  $accomodation, $image1, $image1a, $image2, $image3, $image4, $image5, $image6);

if($insertproperty == 0){
			echo $generalerror = "Error uplaoding files(s).";
		}else{
			echo $generalerror = "Files Uploaded.";
		}
	}

}


?>

Link to comment
Share on other sites

try this

change

		if($image1exists == 1){

			$image1file = $imagedir.$timest."AA".basename($_FILES['image1']['name']);
			//ADD THIS
			echo "I am set:";
			var_dump($image1file);
		}

 

to

		if($image1exists == 1){

			$image1file = dirname(__FILE__)."/".$imagedir.$timest."AA".basename($_FILES['image1']['name']);
			//ADD THIS
			echo "I am set:";
			var_dump($image1file);
		}

Link to comment
Share on other sites

Ok,

 

I ran that and got the below result. I thumbnail still uploaded as a black 100x100 image, but the main image uploaded fine as usual.

 


Testing123:array(6) { ["image1"]=>  array(5) { ["name"]=>  string(9) "house.jpg" ["type"]=>  string(10) "image/jpeg" 

["tmp_name"]=>  string(14) "/tmp/phpaclUz9" ["error"]=>  int(0) ["size"]=>  int(82082) } ["image2"]=>  array(5) { 

["name"]=>  string(0) "" ["type"]=>  string(0) "" ["tmp_name"]=>  string(0) "" ["error"]=>  int(4) ["size"]=>  int(0) } 

["image3"]=>  array(5) { ["name"]=>  string(0) "" ["type"]=>  string(0) "" ["tmp_name"]=>  string(0) "" ["error"]=>  int(4) 

["size"]=>  int(0) } ["image4"]=>  array(5) { ["name"]=>  string(0) "" ["type"]=>  string(0) "" ["tmp_name"]=>  string(0) "" 

["error"]=>  int(4) ["size"]=>  int(0) } ["image5"]=>  array(5) { ["name"]=>  string(0) "" ["type"]=>  string(0) "" 

["tmp_name"]=>  string(0) "" ["error"]=>  int(4) ["size"]=>  int(0) } ["image6"]=>  array(5) { ["name"]=>  string(0) "" 

["type"]=>  string(0) "" ["tmp_name"]=>  string(0) "" ["error"]=>  int(4) ["size"]=>  int(0) } } I am set:string(71) 

"/home/mysite/www/dub/admin/property_images/1194110836AAhouse.jpg"

Link to comment
Share on other sites

Umm... I am not quite sure whats happining now :) .. The page just seems to reload blank with noting on it accept it prints the URL/ address of the page at the top.

 

Below is the exact script I ran.

 


<?php


session_start();

error_reporting(0);

include('../params/params.php');
include_once('thumbnail.inc.php');

if(!isset($_SESSION['valid_admin']))
{
	header("Location:index.php");
}


	$error = "";
	$image2 = "";


$process = "";
$process = isset($_POST['process']) ? $_POST['process'] : '';

$countyerror=""; $locationerror=""; $typeerror=""; $addresserror=""; $priceerror=""; $descriptionerror="";$bedroomerror="";
if ($process != "execute")
{
//not being submitted...
}
else
{	



$county=""; $location=""; $type=""; $price="";$bedrooms="";$sale_type="";$description="";$accomodation="";

 $county = $_POST['county'];
 $location = $_POST['location'];
 $type = $_POST['type'];

 $address = $_POST['address'];
 $price = $_POST['price'];
 $bedrooms = $_POST['bedrooms'];

 $sale_type = $_POST['sale_type'];
 $description = $_POST['description'];
 $features = $_POST['features'];

 $prop = $_POST['prop'];

 $accomodation = $_POST['accomodation'];



if($county == ""){
		$countyerror = "Please select a county.";
		$error=1;
	}elseif($location == ""){
		$locationerror = "Please select a location.";
		$error=1;
	}elseif($type == ""){
		$typeerror = "Please select a property type.";
		$error=1;
	}elseif($address == ""){
		$addresserror = "Please enter an address for this property.";
		$error=1;
	}elseif($price == ""){
		$priceerror = "Please enter a price for this property.";
		$error=1;
	}elseif($description == ""){
		$descriptionerror = "Please enter a description for this property.";
		$error=1;
	}

	if($error == 1){
		//an error occured cant save...
	}else{




$imagedir = "property_images/";

	$timest = time();

	$image1 = $_FILES['image1']['tmp_name'];
                echo "Testing123:";
                var_dump($_FILES);


	    if($image1 != ""){
			$image1exists = 1; 
			$includesimage = '1';

		}


		$image1exists="";
		$image1a=""; 


		if($image1exists == 1){

			$image1file = $imagedir.$timest."AA".basename($_FILES['image1']['name']);
			//ADD THIS
			echo "I am set:";
			var_dump($image1file);
		}


		if($image1exists)
                         {
                             $image1 = $imagedir.$timest."AA".basename($_FILES['image1']['name']);
                         }


		if($image1exists)
                        {
                             $image1a = $imagedir."THUMB".$timest."AA".basename($_FILES['image1']['name']);
                        }



		if($_FILES['image1']['tmp_name'] != ""){

			list($width, $height, $type, $attr) = getimagesize($_FILES['image1']['tmp_name']);
			$check = move_uploaded_file($_FILES['image1']['tmp_name'], $image1file);
			var_dump($check, $image1file); 

			if($width > $height){ $istaller = "0";}
			if($width < $height){ $istaller = "1";}
			if($width == $height){ $istaller = "2";}


				$thumb = new Thumbnail($image1file);
			if($istaller == "0"){
				$thumb->resize('0','100');
				$thumb->cropFromCenter('100');
				}elseif($istaller == "1"){
				$thumb->resize('100','0');
				$thumb->cropFromCenter('100');
			}else{
				$thumb->resize('100','100');
			}
			$thumb->save($image1a,100);
			if($height > "650"){
			$thumb2 = new Thumbnail($image1file);
				if($istaller == "0"){
					$thumb2->resize('0','650');
					$thumb2->cropFromCenter('650');
					}elseif($istaller == "1"){
					$thumb2->resize('650','0');
					$thumb2->cropFromCenter('650');
				}else{
					$thumb2->resize('650','650');
				}
				$thumb2->save($image1,100);
			}
		}



$insertproperty="";
insertproperty($county, $location, $type, $address, $price, $bedrooms, $sale_type, $description, $features, $accomodation, $image1, $image1a, $image2, $image3, $image4, $image5, $image6, $prop);

if($insertproperty == 0){
			echo $generalerror = "Error uplaoding files(s).";
		}else{
			echo $generalerror = "Files Uploaded.";
		}
	}

}


?>

Link to comment
Share on other sites

Scratch that last post! I Put the below variables in the wrong place..

 


$image1exists="";
$image1a=""; 

 

Ok when I added that line you said I got...

 


Testing123:array(6) { ["image1"]=>  array(5) { ["name"]=>  string(9) "house.jpg" ["type"]=>  string(10) "image/jpeg" 

["tmp_name"]=>  string(14) "/tmp/phpud7aBT" ["error"]=>  int(0) ["size"]=>  int(82082) } ["image2"]=>  array(5) { 

["name"]=>  string(0) "" ["type"]=>  string(0) "" ["tmp_name"]=>  string(0) "" ["error"]=>  int(4) ["size"]=>  int(0) } 

["image3"]=>  array(5) { ["name"]=>  string(0) "" ["type"]=>  string(0) "" ["tmp_name"]=>  string(0) "" ["error"]=>  int(4) 

["size"]=>  int(0) } ["image4"]=>  array(5) { ["name"]=>  string(0) "" ["type"]=>  string(0) "" ["tmp_name"]=>  string(0) ""

["error"]=>  int(4) ["size"]=>  int(0) } ["image5"]=>  array(5) { ["name"]=>  string(0) "" ["type"]=>  string(0) "" 

["tmp_name"]=>  string(0) "" ["error"]=>  int(4) ["size"]=>  int(0) } ["image6"]=>  array(5) { ["name"]=>  string(0) "" 

["type"]=>  string(0) "" ["tmp_name"]=>  string(0) "" ["error"]=>  int(4) ["size"]=>  int(0) } } I am set:string(37) 

"property_images/1194126236AAhouse.jpg" bool(true) string(37) "property_images/1194126236AAhouse.jpg" 

Link to comment
Share on other sites

Erm.. did you do this ?

 

try this

change

		if($image1exists == 1){

			$image1file = $imagedir.$timest."AA".basename($_FILES['image1']['name']);
			//ADD THIS
			echo "I am set:";
			var_dump($image1file);
		}

 

to

		if($image1exists == 1){

			$image1file = dirname(__FILE__)."/".$imagedir.$timest."AA".basename($_FILES['image1']['name']);
			//ADD THIS
			echo "I am set:";
			var_dump($image1file);
		}

Link to comment
Share on other sites

Tried it with that there and I got...

 

Thumbnail still uploaded as a black image. This is the strangest thing I've ever come across in my life!

 


Testing123:array(6) { ["image1"]=>  array(5) { ["name"]=>  string(9) "house.jpg" ["type"]=>  string(10) "image/jpeg" 

["tmp_name"]=>  string(14) "/tmp/phpb7VdRV" ["error"]=>  int(0) ["size"]=>  int(82082) } ["image2"]=>  array(5) { 

["name"]=>  string(0) "" ["type"]=>  string(0) "" ["tmp_name"]=>  string(0) "" ["error"]=>  int(4) ["size"]=>  int(0) } 

["image3"]=>  array(5) { ["name"]=>  string(0) "" ["type"]=>  string(0) "" ["tmp_name"]=>  string(0) "" ["error"]=>  int(4) 

["size"]=>  int(0) } ["image4"]=>  array(5) { ["name"]=>  string(0) "" ["type"]=>  string(0) "" ["tmp_name"]=>  string(0) "" 

["error"]=>  int(4) ["size"]=>  int(0) } ["image5"]=>  array(5) { ["name"]=>  string(0) "" ["type"]=>  string(0) "" 

["tmp_name"]=>  string(0) "" ["error"]=>  int(4) ["size"]=>  int(0) } ["image6"]=>  array(5) { ["name"]=>  string(0) "" 

["type"]=>  string(0) "" ["tmp_name"]=>  string(0) "" ["error"]=>  int(4) ["size"]=>  int(0) } } I am set:string(71) 

"/home/mysite/www/dub/admin/property_images/1194138220AAhouse.jpg" bool(true) string(71) 

"/home/mysite/www/dub/admin/property_images/1194138220AAhouse.jpg"

Link to comment
Share on other sites

i gave the code a quick clean up.. try it now

 

<?php
session_start();

include('../params/params.php');
include_once('thumbnail.inc.php');


if(!isset($_SESSION['valid_admin']))
{
	header("Location:index.php");
}

$process = "";
$process = isset($_POST['process']) ? $_POST['process'] : '';

if ($process != "execute")
{
//not being submitted...
}else{	
$county=""; $location=""; $type=""; $price="";$bedrooms="";$sale_type="";$description="";$accomodation="";
$county = $_POST['county'];
$location = $_POST['location'];
$type = $_POST['type'];

$address = $_POST['address'];
$price = $_POST['price'];
$bedrooms = $_POST['bedrooms'];

$sale_type = $_POST['sale_type'];
$description = $_POST['description'];
$features = $_POST['features'];

$accomodation = $_POST['accomodation'];

if($county == "")
{
	$countyerror = "Please select a county.";
	$error=1;
}elseif($location == ""){
	$locationerror = "Please select a location.";
	$error=1;
}elseif($type == ""){
	$typeerror = "Please select a property type.";
	$error=1;
}elseif($address == ""){
	$addresserror = "Please enter an address for this property.";
	$error=1;
}elseif($price == ""){
	$priceerror = "Please enter a price for this property.";
	$error=1;
}elseif($description == ""){
	$descriptionerror = "Please enter a description for this property.";
	$error=1;
}

if($error == 1)
{
	//an error occured cant save...
}else{
	$imagedir = dirname(__FILE__)."/property_images/";

	$timest = time();

	$image1 = $_FILES['image1']['tmp_name'];

    if($image1 != "")
    {
		$image1exists = 1; 
		$includesimage = '1';
	}

	$image1exists="";
	$image1a=""; 

	if($image1exists == 1)
	{
		$image1file = $imagedir.$timest."AA".basename($_FILES['image1']['name']);
		$image1 = $imagedir.$timest."AA".basename($_FILES['image1']['name']);
		$image1a = $imagedir."THUMB".$timest."AA".basename($_FILES['image1']['name']);

		if($_FILES['image1']['tmp_name'] != "")
		{
			list($width, $height, $type, $attr) = getimagesize($_FILES['image1']['tmp_name']);
			$C = move_uploaded_file($_FILES['image1']['tmp_name'], $image1file);
			if(!$C) die("Upload Failed #1");
			if($width > $height){ $istaller = "0";}
			if($width < $height){ $istaller = "1";}
			if($width == $height){ $istaller = "2";}

			$thumb = new Thumbnail($image1file);
			if($istaller == "0")
			{
				$thumb->resize('0','100');
				$thumb->cropFromCenter('100');
			}elseif($istaller == "1"){
				$thumb->resize('100','0');
				$thumb->cropFromCenter('100');
			}else{
				$thumb->resize('100','100');
			}
			$thumb->save($image1a,100);
			if($height > "650")
			{
				$thumb2 = new Thumbnail($image1file);
				if($istaller == "0")
				{
					$thumb2->resize('0','650');
					$thumb2->cropFromCenter('650');
				}elseif($istaller == "1"){
					$thumb2->resize('650','0');
					$thumb2->cropFromCenter('650');
				}else{
					$thumb2->resize('650','650');
				}
					$thumb2->save($image1,100);
			}
		}

		$insertproperty="";
		insertproperty($county, $location, $type, $address, $price, $bedrooms, $sale_type, $description, $features,  $accomodation, $image1, $image1a, $image2, $image3, $image4, $image5, $image6);

		if($insertproperty == 0)
		{
			echo $generalerror = "Error uplaoding files(s).";
		}else{
			echo $generalerror = "Files Uploaded.";
		}
	}
}
}


?>

Link to comment
Share on other sites

I got your code to run there. You had $image1exists=""; after it was set..

 


$timest = time();

	$image1 = $_FILES['image1']['tmp_name'];

	$image1exists="";
	$image1a=""; 

    if($image1 != "")
    {
		$image1exists = 1; 
		$includesimage = '1';
	}

 

 

The thumbnail still uploaded as a black image again. If we cant get this to work, is there any workaround or other thumbnail code you could advise in putting in its place. Its just strange that the code works on my other sites! :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.