Welcome to Geeklog, Anonymous Thursday, April 25 2024 @ 04:53 pm EDT

Geeklog Forums

Random Member Block


Status: offline

comicbookguy

Forum User
Regular Poster
Registered: 05/15/04
Posts: 97
I have spent quite a bit of time trying to figure out this error with no luck. Here is the error message I am getting:
Text Formatted Code
Warning: getimagesize(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/***/system/lib-custom.php on line 365

Warning: getimagesize(http://www.planetdouglas.com/images/userphotos/birdgirl.jpg): failed to open stream: Permission denied in /home/***/system/lib-custom.php on line 365

Warning: Division by zero in /home/***/system/lib-custom.php on line 379


 


I have changed the name of my database (to protect the innocent) to ***. The problem is with the random member block which randomly displays a random members image.

If anyone has any ideas I would appreciate your help.
Thank you.
 Quote

Status: offline

comicbookguy

Forum User
Regular Poster
Registered: 05/15/04
Posts: 97
Here is the code from my lib-custom.php file beginning at line 363.
Text Formatted Code
// Get and size Picture
        $uphoto_url = "{$_CONF['site_url']}/images/userphotos/$uinfo[photo]";
        $uphoto_size = getimagesize($uphoto_url); // returns an array
        $uphoto_width = $uphoto_size[0];
        $uphoto_height = $uphoto_size[1];
       
        // determine which dimension is larger
        if ($uphoto_height > $uphoto_width) {
                $largest = "uphoto_height";
        } elseif ($uphoto_width > $uphoto_height) {
                $largest = "uphoto_width";
        } else { // they are equal
                $largest = "uphoto_height";
        }
       
        // determines the percentage of shrinkage we'll need to use
        $shrink_amount = ($image_max_bounds*100) / $$largest;
        $shrink_amount = ceil($shrink_amount);
       
        if ($shrink_amount > 99) { // it's already smaller - don't change it
               
                $iwidth = $uphoto_width;
                $iheight = $uphoto_height;
               
        } else { // determine the new image size after shrinking
       
                $iwidth = ceil($uphoto_width * ($shrink_amount / 100));
                $iheight = ceil($uphoto_height * ($shrink_amount / 100));
       
        }
 
 Quote

Status: offline

comicbookguy

Forum User
Regular Poster
Registered: 05/15/04
Posts: 97
bump
 Quote

Status: offline

zipstart

Forum User
Chatty
Registered: 09/13/04
Posts: 60
What version of PHP are you using? URL support for getimagesize() wasn't added until 4.0.5.
 Quote

Status: offline

zipstart

Forum User
Chatty
Registered: 09/13/04
Posts: 60
...and try changing $$largest to $largest.
 Quote

Status: offline

comicbookguy

Forum User
Regular Poster
Registered: 05/15/04
Posts: 97
What version of PHP are you using?

I am using 4.3.8

try changing $$largest to $largest.

I thought about that myself but I have been told by a php guy that that is not the problem. I will give it a try anyway and see what happens.

I think it is a logic problem with resizing the images. I suspect the images that are causing the errors are all the same size.

Thank you for the help.
 Quote

Status: offline

NeoNecro

Forum User
Regular Poster
Registered: 02/07/04
Posts: 90
I don't know what code you're using before the function that derterminates the image size, but could it be that it doesn't work if the user has no avatar?
grtz
dimis-site.be
 Quote

Status: offline

comicbookguy

Forum User
Regular Poster
Registered: 05/15/04
Posts: 97
Here is the whole thing:
Text Formatted Code
function phpblock_randMember() {

        global $_CONF;

        // this function pulls a random member's information
        // and displays it in a block - only if they have a photo uploaded though
       
        // written by Benjamin Costello of http://chilax.com/ <benjamin@chilax.com>
        // idea inspired by MemberPhotos hack by Mr. GXBlock (http://www.gxblock.com/)
       
        // set the preferred maximum size (will fit within a square this size)
        $image_max_bounds = "100";
        $pathtoimages = $_CONF['path_html'] . 'images/userphotos';
       
       
        // Do database query
        $sql = "SELECT * FROM gl_users WHERE photo <> 'NULL' && (photo <> '') ORDER BY RAND() LIMIT 1";
        $result = mysql_query($sql);
        $uinfo = mysql_fetch_array($result);
       
       
        // Get and size Picture
        $uphoto_url = "{$_CONF['site_url']}/images/userphotos/$uinfo[photo]";
        $uphoto_size = getimagesize($uphoto_url); // returns an array
        $uphoto_width = $uphoto_size[0];
        $uphoto_height = $uphoto_size[1];
       
        // determine which dimension is larger
        if ($uphoto_height > $uphoto_width) {
                $largest = "uphoto_height";
        } elseif ($uphoto_width > $uphoto_height) {
                $largest = "uphoto_width";
        } else { // they are equal
                $largest = "uphoto_height";
        }
       
        // determines the percentage of shrinkage we'll need to use
        $shrink_amount = ($image_max_bounds*100) / $$largest;
        $shrink_amount = ceil($shrink_amount);
       
        if ($shrink_amount > 99) { // it's already smaller - don't change it
               
                $iwidth = $uphoto_width;
                $iheight = $uphoto_height;
               
        } else { // determine the new image size after shrinking
       
                $iwidth = ceil($uphoto_width * ($shrink_amount / 100));
                $iheight = ceil($uphoto_height * ($shrink_amount / 100));
       
        }
       
       
        $retval .= "<CENTER>";
        $retval .= "<IMG SRC="{$_CONF['site_url']}/images/userphotos/$uinfo[photo]" WIDTH="$iwidth" HEIGHT="$iheight" ALT="" VSPACE=4>";
        $retval .= "n<BR>n";
        $retval .= "<B><A HREF="{$_CONF['site_url']}/users.php?mode=profile&uid=$uinfo[uid]">$uinfo[username]</A></B>";
       
        return $retval;
       
}
?>
 
 Quote

Status: offline

zipstart

Forum User
Chatty
Registered: 09/13/04
Posts: 60
Looks like it's failing on users with a space in their name. Place this before // Get and size Picture...

Text Formatted Code
//replace spaces in user photo name
        $user_photo = str_replace(" ","%20",$uinfo[photo]);

 


and replace $uinfo[photo] with $user_photo. Works fine on my site after that.
 Quote

Status: offline

comicbookguy

Forum User
Regular Poster
Registered: 05/15/04
Posts: 97
Thanks. I will try that tonight when i get home.
 Quote

All times are EDT. The time is now 04:53 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content