QuickGallery PHP restriction?

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by tyharo195, May 14, 2014.

  1. tyharo195

    tyharo195 New Member

    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    I'm trying to use QuickGallery but each time I load the index page I get the following errors:
    Code:
    Warning: opendir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/home/tyharote:/usr/lib/php:/usr/php4/lib/php:/usr/local/lib/php:/usr/local/php4/lib/php:/tmp) in /home/tyharote/public_html/cphoto/gallery/index.php on line 65
    
    Warning: opendir(/): failed to open dir: Operation not permitted in /home/tyharote/public_html/cphoto/gallery/index.php on line 65
    
    Warning: readdir() expects parameter 1 to be resource, boolean given in /home/tyharote/public_html/cphoto/gallery/index.php on line 66
    The code for this sections is here (lines 62 - 74):
    Code:
     <?php
              $imgdir = $gallery . '/';
              $allowed_types = array('png','jpg','jpeg','gif');
              $dimg = opendir($imgdir);
              while($imgfile = readdir($dimg))
              {
                if( in_array(strtolower(substr($imgfile,-3)),$allowed_types) OR
                  in_array(strtolower(substr($imgfile,-4)),$allowed_types) )
                {$a_img[] = $imgfile;}
              }
               $totimg = count($a_img);
               for($x=0; $x < $totimg; $x++){ echo "<a href='" . $imgdir . $a_img[$x] . "' rel='gallery'><img src='thumb.php?file=$imgdir".$a_img[$x]."' /></a>"; }
            ?>
    The QuickGallery code can be found here and I havent modified or added the base code.
    https://github.com/mojeda/QuickGallery

    Any help is appreciated, I'd really like to get this php gallery working it been bugging me for the last few days.
     
  2. descalzo

    descalzo Grim Squeaker Community Support

    Messages:
    9,375
    Likes Received:
    327
    Trophy Points:
    83
    You have $gallery set to the empty string -- at least that is what the Error Message is saying.
     
    • Informative Informative x 1
  3. tyharo195

    tyharo195 New Member

    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    $imgdir = $gallery . '/'; is supposed to point towards the directory where the photos are stored I believe. The index.php file is located in another folder called gallery, a dricetory one level down from the rest of the site, where the folders with the images are located. I googled the first error and apparently its a php security error but I'm not a master at php. I can submit the code for to php pages if it will help and the error can be viewed here : http://tyharotest.x10host.com/cphoto/gallery/
    the links on the side work but the images preview wont show, if you click an image it will display though.
     
    Last edited: May 14, 2014
  4. descalzo

    descalzo Grim Squeaker Community Support

    Messages:
    9,375
    Likes Received:
    327
    Trophy Points:
    83
    Correct. But if $gallery == "", then you get $imgdir == "/" which is WRONG.

    $gallery should be something like "/home/yourCPanelUserName/public_html/wheretheimagesare"

    Try posting everything above what you have already posted.
     
    • Informative Informative x 1
  5. tyharo195

    tyharo195 New Member

    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Alright now we are getting some where, I changed the code to the following:
    Code:
    $imgdir = $gallery . '/home/tyharote/public_html/cphoto/gallery';
    but now I'am getting these errors when i click on a folder link in the gallery, its as though its reading the path backwards. FYI 'fake' is the name of the directory clicked on which is holding some photos:
    Code:
    Warning: opendir(fake/home/tyharote/public_html/cphoto/gallery): failed to open dir: No such file or directory in /home/tyharote/public_html/cphoto/gallery/index.php on line 65
    
    Warning: readdir() expects parameter 1 to be resource, boolean given in /home/tyharote/public_html/cphoto/gallery/index.php on line 66
     
    Last edited: May 14, 2014
  6. tyharo195

    tyharo195 New Member

    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Thanks for helping me out so far descalzo! Ok so I fixed the errors by changing the code to:
    Code:
    $imgdir =  '/home/tyharote/public_html/cphoto/gallery/' . $gallery . '/';
    But the image previews aren't working and the images wont load when clicked anymore, all you get is an error saying "The requested content cannot be loaded. please try again later". When I hover over the possible image link the path listed is correct but the image just wont load.
    Here is the complete php section, hopefully it will help:
    Code:
      <?php
              $imgdir =  '/home/tyharote/public_html/cphoto/gallery/' . $gallery . '/';
              $allowed_types = array('png','jpg','jpeg','gif');
              $dimg = opendir($imgdir);
              while($imgfile = readdir($dimg))
              {
                if( in_array(strtolower(substr($imgfile,-3)),$allowed_types) OR
                  in_array(strtolower(substr($imgfile,-4)),$allowed_types) )
                {$a_img[] = $imgfile;}
              }
               $totimg = count($a_img);
               for($x=0; $x < $totimg; $x++){ echo "<a href='" . $imgdir . $a_img[$x] . "' rel='gallery'><img src='thumb.php?file=$imgdir".$a_img[$x]."' /></a>"; }
            ?>
     

Share This Page