Jump to content

Recommended Posts

ok I have a little photo gallery on a site. I made up a little bit of code that resizes the image if it is too big.

The script works fine when it's on my local computer, but when I upload it the script takes the image size of the image after the one it's supposed to, but outputs the image it is supposed to.

If I have image1 and image2, When I try and get the size of image1 it takes the size of image2, but still outputs image1...I don't get it...here is my code, please help if you can!

[code]    if (!isset($userid) or trim($userid)=='') {
      $gal = 1; }
    if (!isset($pic) or trim($pic)=='') {
      $pic = 1; }
    $dir= "custphotos/gallery".$userid;
    @$d = dir($dir);
              
    if ($d) {
      while($entry=$d->read()) {  
        $entry = preg_replace("/ /","%20",$entry);
        $pos = strpos (strtolower($entry), ".jpg");
        if (!($pos === false)) {  
          $arr_pic[] = $dir."/".$entry; } }
      $d->close(); }
    
    $CONST_WIDTH = 250;
    //Find image h and w
    $size = getimagesize($arr_pic[$pic-1]);
    
    $w = $size[0];
    $h = $size[1];
    
    if($w > $CONST_WIDTH){
        //Find %
        $percent = $w / $CONST_WIDTH;
        $w = $w / $percent;
        $h = $h / $percent;
    }
    
    @sort ($arr_pic);    
    $total  = sizeof($arr_pic);
    echo "<div align=\"center\"><img width=\"$w\" height=\"$h\" src=".$arr_pic[$pic-1]."><br>";[/code]
Link to comment
https://forums.phpfreaks.com/topic/5900-image-problems/
Share on other sites

[!--quoteo(post=361711:date=Apr 4 2006, 09:21 PM:name=cmgmyr)--][div class=\'quotetop\']QUOTE(cmgmyr @ Apr 4 2006, 09:21 PM) [snapback]361711[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Local: 4.4.0
Server: 4.3.10

Thanks,
-Chris
[/quote]

looking at your code and at the post by [b]Barand[/b], I think he's hit the nail on the head. Have you tried what he suggested? Lose the @sort line (for the purpose of testing) and see what happens.
Link to comment
https://forums.phpfreaks.com/topic/5900-image-problems/#findComment-23977
Share on other sites

Ok...that fixed the size problem...but caused another.

The customers are allowed 5 photos. I originally had it set up to where they can re-name the photos to change the order of them on their profile, but now it's not working like that. The way that it is set up now it shows the second picture [$pic-1] when I try [$pic-2] none of the images show up.

Is there a way to get around this one?

Thanks
Link to comment
https://forums.phpfreaks.com/topic/5900-image-problems/#findComment-24053
Share on other sites

try changing the second part of your code

[code]    $CONST_WIDTH = 250;
    @sort ($arr_pic);

    foreach ($arr_pic as $picfile) {
        //Find image h and w
        $size = getimagesize($picfile);

        $w = $size[0];
        $h = $size[1];

        if($w > $CONST_WIDTH){
            //Find %
            $percent = $w / $CONST_WIDTH;
            $w = $w / $percent;
            $h = $h / $percent;
        }
        echo "<div align=\"center\"><img width=\"$w\" height=\"$h\" src=\"$picfile\"><br>";
    }
[/code]
Link to comment
https://forums.phpfreaks.com/topic/5900-image-problems/#findComment-24126
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.