Jump to content


Photo

Watermarking + MySQL + PHP Problems


  • Please log in to reply
6 replies to this topic

#1 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 27 March 2006 - 11:33 AM

This thread is based on [a href=\"http://aimmultimedia.com/viewpage.php?page_id=3\" target=\"_blank\"]http://aimmultimedia.com/viewpage.php?page_id=3[/a] , where there are couple of problems. (Try uploading for yourself).

First problem: My first query runs perfectly, but my 2nd mysql query doesn't. Whats wrong?

First Query
PHP Code:
$viewid = $_GET["id"];
$result = mysql_query("SELECT * FROM registered_files WHERE viewid = '$viewid'");
$myrow = mysql_fetch_array($result);

Second Query
PHP Code:
<?php $result2  = mysql_query("UPDATE registered_files SET hits=hits+1 WHERE id = '$viewid'") or die (mysql_error());
$rowyourboat = mysql_fetch_array($result2);
echo $rowyourboat["hits"] ?>


[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/lpxxfain/public_html/membersimage.php on line 36[/quote]




Second Question: On the same upload page, I recently installed a watermarking system, and it works fine. The problem is when it watermarks small images, it totally messes it up. Is there any way so that it doesn't water mark images that are too small?

Example Normal : [a href=\"http://aimmultimedia.com/membersimage.php?id=Gdubs!4\" target=\"_blank\"]http://aimmultimedia.com/membersimage.php?id=Gdubs!4[/a]
Example Small : [a href=\"http://aimmultimedia.com/membersimage.php?id=Affiliate8\" target=\"_blank\"]http://aimmultimedia.com/membersimage.php?id=Affiliate8[/a]


Source:

function_watermark.php
PHP Code:
<?php

function watermark($SourceFile, $WatermarkFile, $SaveToFile = NULL)

{

    $watermark = @imagecreatefrompng($WatermarkFile)


    or exit('Cannot open the watermark file.');

    imageAlphaBlending($watermark, false);

    imageSaveAlpha($watermark, true);

    $image_string = @file_get_contents($SourceFile)


    or exit('Cannot open image file.');

    $image = @imagecreatefromstring($image_string)

    or exit('Not a valid image format.');

    $imageWidth=imageSX($image);

    $imageHeight=imageSY($image);


    $watermarkWidth=imageSX($watermark);

    $watermarkHeight=imageSY($watermark);

    $coordinate_X = ( $imageWidth - 5) - ( $watermarkWidth);


    $coordinate_Y = ( $imageHeight - 5) - ( $watermarkHeight);

    imagecopy($image, $watermark, $coordinate_X, $coordinate_Y,


        0, 0, $watermarkWidth, $watermarkHeight);

    if(!($SaveToFile)) header('Content-Type: image/jpeg');

    imagejpeg ($image, $SaveToFile, 100);


    imagedestroy($image);

    imagedestroy($watermark);

    if(!($SaveToFile)) exit;

}

?>




membersupload.php
PHP Code:
<?php
ob_start();

UPLOAD CODE WAS HERE

header("Location: http://aimmultimedia.com/process2.php?id=$id&ext=$ext&viewid=$viewid");

};
ob_end_flush();


?>



Process2.php
PHP Code:
<?php
ob_start();
// The image should be located in a non public directory
$id = $_GET['id'];
$ext = $_GET['ext'];
$viewid = $_GET['viewid'];


$image_location = '/home/lpxxfain/public_html/members/images/'.$id. '.' .$ext;



// Locate the watermark file wherever you choose (remember PNG format)

$watermark_location = '/home/lpxxfain/public_html/members/water.png';



// Location where you want to save the created watermarked file

$save_watermarked_file_to = '/home/lpxxfain/public_html/members/images/imagesbin/'.$id. '.' .$ext;




// Include the watermarking function file

require_once($_SERVER['DOCUMENT_ROOT'] . '/function_watermark.php');



// Watermark the image and save it to file

watermark($image_location, $watermark_location, $save_watermarked_file_to);

header("Location: http://aimmultimedia.com/membersimage.php?id=$viewid");
ob_end_flush();

?>




3rd Question: Is there any way so that if there is no $_GET['editid'] then the script runs normally, and when there is a $_GET it run's something different?



Help would be greatly appreciated.

-AIMMultimedia.com

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 27 March 2006 - 11:42 AM

Unable to establish connection to MySQL
2002 : Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

i think that you have even bigger problems lol
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 27 March 2006 - 12:24 PM

No, it's fixed. ;)

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 27 March 2006 - 12:26 PM

[!--quoteo(post=358856:date=Mar 27 2006, 12:24 PM:name=lpxxfaintxx)--][div class=\'quotetop\']QUOTE(lpxxfaintxx @ Mar 27 2006, 12:24 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
No, it's fixed. ;)
[/quote]

Can you post the fix for other users like me cheers.

I was getting right into your site untill i relise that you got a 3rd party script lol.
cool!

All the best redarrow.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 27 March 2006 - 12:43 PM

the whole thing fixed? or just that error i stated?

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php $result2 = mysql_query("UPDATE registered_files SET hits=hits+1 WHERE id = '$viewid'") or die (mysql_error());
$rowyourboat = mysql_fetch_array($result2);
echo $rowyourboat["hits"] ?>[/quote]

You can't echo an array of this because it's an update therefore is doesn't select any data you will need

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php
$result2 = mysql_query("UPDATE registered_files SET hits=(hits+1) WHERE id = '$viewid'") or die (mysql_error());
$result3 = mysql_query("SELECT hits FROM registered_files WHERE id = '$viewid'") or die (mysql_error());
$rowyourboat = mysql_fetch_array($result3);
echo $rowyourboat["hits"] ?>
[/quote]


That should do the job mate :)
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#6 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 27 March 2006 - 11:02 PM

Well, the error is gone but it just comes out as nothing. Preview: [a href=\"http://aimmultimedia.com/membersimage.php?id=asgdsgdsaga10\" target=\"_blank\"]http://aimmultimedia.com/membersimage.php?id=asgdsgdsaga10[/a]

I have the tables set up correctly, I am almost certain. I have the 'hits' field on int(10)

Also, does anyone have any ideas about the other questions, like the watermarking one?

Thanks a LOT.

#7 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 28 March 2006 - 12:05 AM

On the water marking....

I think I saw in the script that you grab the dimensions of each image. Simple if statement to check the watermark is smaller than the image - if it is use the watermark - if not do something else (I suggest you just put some text on), or nothing.

Your first problem with the query has been sorted out.

The final one about whether $_GET['editid'] is set....

another if statment...

if (isset($_GET['editid'] )) {
do something
} else {
do soemthing else
}
follow me on twitter @PHPsycho




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users