sql into variable only half works

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lBurt0n
Forum Newbie
Posts: 6
Joined: Thu May 18, 2006 3:48 pm

sql into variable only half works

Post by lBurt0n »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Greetings,

This is my first post here, and as much as I'd like it to be starting off giving someone help its quite the opposite. 

My problem is this. I've been trying to make a gallery system where you can upload images, crop the thumbnail and store all teh image data and comments in a mysql table. I've got a great script I found to cut out the thumbnails and have been integrating it into my scripts. The script takes all the file data, uploads the file, adds all the data to the mySQL database and tehn on the cropping script takes the desired filename from the database and uses that to name the thumb nail... Here is the script I have

Code: Select all

$tn_gallocation = "gallery_images/thumbs" ;
$tn_prefix = "tn_" ;

$date = $_POST['date'] ;
	$query = "SELECT id, filename FROM burt0n_thelab.images WHERE timestamp = '$date'" ;

	$result = $db->readquery($query);
		if (!$result) {
   			echo 'Could not run query: ' . mysql_error();
   			exit;
		}
	$row = mysql_fetch_array($result);

	$i = $row[0] ;
	$destfile = $row['filename'] ;
	
	$ci = new cropInterface();
	$savefile = "$tn_gallocation/$tn_prefix" . "$destfile" ; //THE DESTFILE IS GIVING IT PROBLEMS
	//$savefile = "$destfile";

	//echo "$destfile" ;
	//echo "$savefile" ;
	
	if ($_GET['file'])
	{
	    $ci->loadImage($_GET['file']);
		$ci->cropToDimensions($_GET['sx'], $_GET['sy'], $_GET['ex'], $_GET['ey']);
		header('Content-type: image/jpeg');
		$ci->showImage('jpg', 100);
		$ci->saveImage("$savefile", 100) ;
		exit;
	}
I've spent hours with two other coders I know trying to get this to work. The problem is if you echo $savefile you get "gallery_images/thumbs/tn_file.jpg", but as soon as you run it into the saveImage() function it doesn't work. It will only read if your lucky up to the end of the prefix... I've had it save tn_ as a filename a few times, but never the end.

I've tried a million different ways of making $savefile, I've tried mysql_get_rows and mysql_get_arrays and i'm convinced its taht section of code that is doing it. It will echo fine but not in saveImage. If I cut what it echos and put it into saveimage where the $savefile would be it works... I've tried changing the field type that 'filename' is stored in in my mysql table but no luck.

I hope I explained myself well enough, I'm pullling my hair out over this b*****d! I hate the days when the small problems get in the way of the fun work. Cheers for any help in advance... I'm completey stuck.

-Leonard


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Without seeing the saveImage() method from the cropInterface class it's a bit difficult to know why it's not working.
lBurt0n
Forum Newbie
Posts: 6
Joined: Thu May 18, 2006 3:48 pm

Post by lBurt0n »

Sorry... meant to put that in!

Code: Select all

function saveImage($filename, $quality = 100)
	{
		if ($this->_imgFinal == null)
		{
			$this->_debug('saveImage', 'There is no processed image to save.');
			return false;
		}

		$ext = strtolower($this->_getExtension($filename));
		$func = "image$ext";

		if (!@function_exists($func))
		{
			$this->_debug('saveImage', "That file cannot be saved with the function '$func'.");
			return false;
		}

		$saved = false;
		if ($ext == 'png') $saved = $func($this->_imgFinal, $filename);
		if ($ext == 'jpeg') $saved = $func($this->_imgFinal, $filename, $quality);
		if ($saved == false)
		{
			$this->_debug('saveImage', "Could not save the output file '$filename' as a $ext.");
			return false;
		}
		
		return true;
	}
And that uses the debug funtion which is

Code: Select all

function _debug($function, $string)
	{
		if ($this->_showDebug)
		{
			echo "<p><strong style=\"color:#FF0000\">Error in function $function:</strong> $string</p>\n";
		}
	}
And _showDebug is just a variable which is used in this function;


Code: Select all

function canvasCrop($debug = false)
	{
		$this->_showDebug = ($debug ? true : false);
		$this->_gdVersion = (function_exists('imagecreatetruecolor')) ? 2 : 1;
	}

From what I've played about with I don't think its the functions as if you feed it what the $savefile echos it works fine!

EDIT: Just spotted the PHP code thing for posting! Sorry... changing it now
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Code: Select all

$ext = strtolower($this->_getExtension($filename));
$func = "image$ext"; 

if (!@function_exists($func)) {
I assume that the _getExtension() method takes the filename you pass in and extracts the jpg bit from the end. If thats true then function_exists($func) is going to fail, because imagejpg is not a function .. it's imagejpeg().
lBurt0n
Forum Newbie
Posts: 6
Joined: Thu May 18, 2006 3:48 pm

Post by lBurt0n »

Those functions were part f the script I've been integrating with what I've been working on, so they aren't written by me. I've not spent too long looking at them so I've never noticed that before. But its worked fine with the what $savefile should be put in manually so I don't think thats an issue, although I'm not saying I'm right on that...

Code: Select all

function _getExtension($filename)
	{
		$ext  = @strtolower(@substr($filename, (@strrpos($filename, ".") ? @strrpos($filename, ".") + 1 : @strlen($filename)), @strlen($filename)));
		return ($ext == 'jpg') ? 'jpeg' : $ext;
	}
thats the _getExtension function, didn't see that was used before so didn't postr it.

-Leonard
lBurt0n
Forum Newbie
Posts: 6
Joined: Thu May 18, 2006 3:48 pm

Post by lBurt0n »

Just remembered...

Code: Select all

$ci->saveImage("buffer/test.jpg", 100) ;
		copy('buffer/temp.jpg', $savefile) ;
I tried that code as well today in place of what is there, and it saved buffer/test.jpg and then it would go as far as saving "gallery_images/thumbs/tn_" and it would leave off file.jpg, which is what $destfile would be! Which is another reason I think its to do with the way $destfile is being made.
lBurt0n
Forum Newbie
Posts: 6
Joined: Thu May 18, 2006 3:48 pm

Post by lBurt0n »

I know this is an odd problem, and a quirk of php/mysql, but can no one help out?
Post Reply