FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Thumbnail Code... not getting pictures...





Simulator
Ever since the crash, and sometimes before it, my thumbnail code stoped working.

Code:
<?php

  $connection = mysql_connect($host,$user,$password)    #13
       or die ("couldn't connect to server");
  $db = mysql_select_db($database,$connection)          #15
       or die ("Couldn't select database");

         $result2 = mysql_query("SELECT pic FROM pics WHERE id = '".mysql_escape_string($_GET["id"])."'");
            $row = mysql_fetch_array($result2);

extract($row);


         
# Constants

$mAX_WIDTH = 305;
$mAX_HEIGHT = 260;

# Get image location
$image_path = $pic;

# Load image
$img = null;
$ext = strtolower(end(explode('.', $image_path)));
if ($ext == 'jpg' || $ext == 'jpeg') {
    $img = @imagecreatefromjpeg($image_path);
} else if ($ext == 'png') {
    $img = @imagecreatefrompng($image_path);
# Only if your version of GD includes GIF support
} else if ($ext == 'gif') {
    $img = @imagecreatefromgif($image_path);
}

# If an image was successfully loaded, test the image for size
if ($img) {

    # Get image size and scale ratio
    $width = imagesx($img);
    $height = imagesy($img);
    $scale = min($mAX_WIDTH/$width, $mAX_HEIGHT/$height);

    # If the image is larger than the max shrink it
    if ($scale < 1) {
        $new_width = floor($scale*$width);
        $new_height = floor($scale*$height);

        # Create a new temporary image
        $tmp_img = imagecreatetruecolor($new_width, $new_height);

        # Copy and resize old image into new image
        imagecopyresized($tmp_img, $img, 0, 0, 0, 0,
                         $new_width, $new_height, $width, $height);
        imagedestroy($img);
        $img = $tmp_img;       
    }   
}
# Display the image
header("Content-type: image/jpeg");
imagejpeg($img);
imagedestroy($image_file);
imagedestroy($img);

?>


On #13 and #15 the information has been taking out

What happens is, it just shows the alt tag.... What should happen is, you request the image at thumb.php?id="PICTURE ID HERE" it takes the id and outputs the image... but all I get is the alt tag...
Stubru Freak
Are the $host, $user, $pass and $database variables set? I suppose not as you get this error:

Warning: mysql_query(): Access denied for user: 'apache@localhost' (Using password: NO) in /home/simulato/domains/simandsim.com/public_html/thumb.php on line 6
Simulator
Stubru Freak wrote:
Are the $host, $user, $pass and $database variables set? I suppose not as you get this error:

Warning: mysql_query(): Access denied for user: 'apache@localhost' (Using password: NO) in /home/simulato/domains/simandsim.com/public_html/thumb.php on line 6


Yes they are, I just said I took them out....
shalmoli
Check the following options:
1. id is a text/varchar field and not a number(int). Else donot use ' '.
2. mysql_fetch_array returns field values with both the numerical and associative keys, the numerical ones being those extract() can't handle very well.You can prevent that by calling mysql_fetch_array($result,MYSQL_ASSOC) which will return the same result as mysql_fetch_assoc and is extract() friendly.
Simulator
Its ok, its working again
Related topics
Script php about gallery
751 Useful Windows XP Files
Mess.be Thumbnail files
display pictures from www.MESS.be
Help with Website
photo gallery ive been working on
the matrix online - review and pictures
Copying and pasting huge chunks of codes
Auto width\height if picture is wider than a given variable
xMPACT.com is alive!! - And Updated 7-17-2008!!!!
Need help with wordpress Setup
PHP question about passing variables (noob)
Your photography techniques
Travel Tips for an Excursion... to America?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.