Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End fatal error with imgbrowz0r

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #27546
    sharpie
    Member

    Hi

    Other than some HTML and CSS scripts I’ve not done a great deal with websites – having watched the tutorial on imgbrowz0r I thought it would the answer to a gallery I’d like to include on my new photo site.

    So I duly downloaded and followed the tutorial several times and viewed similar code on another site and off I went…

    Sadly though I’m slowly picking up limited PHP knowledge a fatal error in he index.php has me flumaxed, I know it’ll turn out to be something really basic but the error reads Fatal error: Call to undefined method imgbrowz0r::init() in F:xampphtdocsMySiteindex.php on line 137 the code reads $galleries->init();

    Can anyone put me out of my misery and point me in the right direction.

    Cheers

    Jon

    #69451
    sharpie
    Member

    Update – this is the code for index.php which is giving me the fatal error, it’s as copied from the screen cast

    Code:
    dirname(__FILE__).’/gallery’,
    ‘cache_dir’ => dirname(__FILE__).’/cache’,

    ‘main_url’ => ‘http://localhost/test/index.php?q=%path”‘,
    ‘images_url’ => ‘http://localhost/test/gallery’,
    ‘cache_url’ => ‘http://localhost/test/cache’,

    ‘dir_thumbs’ => true,
    ‘random_thumbs’ => true,
    ‘read_thumb_limit’ => 0,
    );

    $gallery = new imgbrowz0r($config);

    ?>





    Photo Gallery

    My photo Gallery

    init();

    $gallery_breadcrumbs = $gallery->breadcrumbs();
    $gallery_pagination = $gallery->pagination();
    $gallery_statistics = $gallery->statistics();

    //displanavigationy
    echo ‘

    ‘, “nt”, $gallery_breadcrumbs, “nt”, $gallery_pagination, “nt”, $gallery_statistics, “n”, ‘

    ‘, “nn”;

    echo $gallery->browse();

    echo “

    “;

    ?>


    this is the code from the imgbrowz0r.php – more or less out of the box from download.

    Code:
    GD is not enabled!

    ‘);

    // Set configuration
    $this->config = array(
    // Directory settings
    ‘images_dir’ => isset($config[‘images_dir’]) ? $config[‘images_dir’] : exit(‘f:xampphtdocsgallery’),
    ‘cache_dir’ => isset($config[‘cache_dir’]) ? $config[‘cache_dir’] : exit(‘f:xampphtdocscache’),

    // Url settings
    ‘main_url’ => isset($config[‘main_url’]) ? $config[‘main_url’] : exit(‘http://localhost/test/index.php?q=%path”‘),
    ‘images_url’ => isset($config[‘images_url’]) ? $config[‘images_url’] : exit(‘http://localhost/test/gallery’),
    ‘cache_url’ => isset($config[‘cache_url’]) ? $config[‘cache_url’] : exit(‘http://localhost/test/cache’),

    // Sorting settings
    ‘sort_by’ => isset($config[‘sort_by’]) && in_array($config[‘sort_by’], array(1, 2, 3)) ? $config[‘sort_by’] : 3,
    ‘sort_order’ => isset($config[‘sort_order’]) && $config[‘sort_order’] === true ? SORT_ASC : SORT_DESC,

    // Thumbnail settings
    ‘thumbs_per_page’ => isset($config[‘thumbs_per_page’]) ? $config[‘thumbs_per_page’] : 12,
    ‘max_thumb_row’ => isset($config[‘max_thumb_row’]) ? $config[‘max_thumb_row’] : 4,
    ‘max_thumb_width’ => isset($config[‘max_thumb_width’]) ? $config[‘max_thumb_width’] : 200,
    ‘max_thumb_height’ => isset($config[‘max_thumb_height’]) ? $config[‘max_thumb_height’] : 200,

    // Time settings
    ‘time_format’ => isset($config[‘time_format’]) ? $config[‘time_format’] : ‘F jS, Y’,
    ‘time_zone’ => isset($config[‘time_zone’]) ? $config[‘time_zone’] : 0,
    ‘enable_dst’ => isset($config[‘enable_dst’]) && $config[‘enable_dst’] === true ? 1 : 0
    );

    // Get current url
    $protocol = (!isset($_SERVER[‘HTTPS’]) || strtolower($_SERVER[‘HTTPS’]) == ‘off’) ? ‘http://’ : ‘https://’;
    $port = (isset($_SERVER[‘SERVER_PORT’]) && (($_SERVER[‘SERVER_PORT’] != ’80’ && $protocol == ‘http://’) || ($_SERVER[‘SERVER_PORT’] != ‘443’ && $protocol == ‘https://’)) && strpos($_SERVER[‘HTTP_HOST’], ‘:’) === false) ? ‘:’.$_SERVER[‘SERVER_PORT’] : ”;
    $current_url = urldecode($protocol.$_SERVER[‘HTTP_HOST’].$port.$_SERVER[‘REQUEST_URI’]);

    // Regex
    preg_match(‘/^’.str_replace(
    array(‘{‘, ‘}’, ‘[‘, ‘]’, ‘?’, ‘(‘, ‘)’, ‘-‘, ‘.’, ‘/’, ‘=’, ‘%PATH%’),
    array(‘{‘, ‘}’, ‘[‘, ‘]’, ‘?’, ‘(‘, ‘)’, ‘-‘, ‘.’, ‘/’, ‘=’, ‘(.*?)’),
    $this->config[‘main_url’]).’$/i’, $current_url, $matches);

    // Set current path/directory and page
    $raw_path = isset($matches[1]) ? trim($matches[1], ‘ /nt’) : false;

    if ($raw_path !== false)
    {
    $this->cur_directory = preg_replace(‘/[^A-Za-z0-9,_ -()[]{}/]/’, ”, substr($raw_path, 0, strrpos($raw_path, ‘/’))).’/’;
    $this->cur_page = (int) substr($raw_path, strrpos($raw_path, ‘/’)+1);
    }
    else
    {
    $this->cur_directory = false; // This should stay a string
    $this->cur_page = 1;
    }

    if ($this->cur_directory == ‘0/’ || $this->cur_directory == ‘/’)
    $this->cur_directory = false;
    }

    // Reads the gallery directories and files
    public function browse()
    {
    @set_time_limit(180); // 3 Minutes

    $output = null;
    $dirs = array();
    $imgs = array();

    $full_path = $this->cur_directory === false ? $this->config[‘images_dir’].’/’ : $this->config[‘images_dir’].’/’.$this->cur_directory;

    // Start capturing output
    ob_start();

    echo ‘

    ‘;

    if (is_dir($full_path) && ($handle = opendir($full_path)))
    {
    // Scan directories and files
    while (($file = readdir($handle)) !== false)
    {
    if (is_dir($full_path.’/’.$file))
    {
    // Exclude . and ..
    if ($file == ‘.’ || $file == ‘..’)
    continue;

    $dirs[] = array(0, $file, ‘dir’, filectime($full_path.’/’.$file));
    }
    else
    {
    // Check if file is an supported image type
    $image_extension = $this->get_ext($file);
    if (!in_array($image_extension, array(‘gif’, ‘jpg’, ‘jpeg’, ‘jpe’, ‘jif’, ‘jfif’, ‘jfi’, ‘png’)))
    continue;

    $imgs[] = array(1, $file, $image_extension, filectime($full_path.’/’.$file));
    }
    }

    closedir($handle);

    // Sort arrays
    if (($count_dirs = count($dirs)) > 0)
    {
    foreach($dirs as $res) $sortAux[] = $res[$this->config[‘sort_by’]];
    array_multisort($sortAux, $this->config[‘sort_order’], $dirs);
    }

    if (($count_imgs = count($imgs)) > 0)
    {
    foreach($imgs as $res2) $sortAux2[] = $res2[$this->config[‘sort_by’]];
    array_multisort($sortAux2, $this->config[‘sort_order’], $imgs);
    }

    // Calculate pages
    $page_count = (int) ceil(($count_dirs + $count_imgs) / $this->config[‘thumbs_per_page’]);
    $this->cur_page = $this->cur_page > 0 && $this->cur_page <= $page_count ? $this->cur_page : 1;

    // Merge and slice arrays
    $items = array_merge($dirs, $imgs);
    $items = array_slice($items, ($this->cur_page -1) * $this->config[‘thumbs_per_page’], $this->config[‘thumbs_per_page’]);
    $item_count = count($items);

    // Create navigation
    $breadcrumbs = ‘

    Breadcrumbs: ‘.$this->breadcrumbs().’

    ‘;
    $pagination = $page_count > 1 ? “ntt”.’

    Pages: ‘.$this->pagination($page_count).’

    ‘ : null;

    // Echo, echo~
    echo “nt”, ‘

    There ‘.($count_dirs !== 1 ? ‘are ‘.$count_dirs.’ directories’ : ‘is 1 directory’).’ and ‘.
    ($count_imgs !== 1 ? $count_imgs.’ images’ : ‘1 image’).’ in this directory.

    ‘, “n”,
    “nt”, ‘

    ‘, “ntt”, $breadcrumbs, $pagination, “nt”, ‘

    ‘, “n”;

    $row_count = 1;
    if ($item_count > 0)
    {
    echo “nt”, ‘

    ‘, “n”;

    foreach ($items as $k => $item)
    {
    if ($item[0] === 1)
    {
    $image_cache_dir = md5($this->cur_directory);
    $image_thumbnail = $image_cache_dir.’/’.$item[1]; // The name of the thumbnail

    if (!is_dir($this->config[‘cache_dir’].’/’.$image_cache_dir))
    mkdir($this->config[‘cache_dir’].’/’.$image_cache_dir, 0777);

    if (!file_exists($this->config[‘cache_dir’].’/’.$image_thumbnail))
    $this->make_thumb($this->cur_directory, $item[1], $image_thumbnail);

    echo “tt”, ‘

    ‘, “n”;

    // Stop capturing output
    $output = ob_get_contents();
    ob_end_clean();

    return $output;
    }

    // Create css rules
    public function output_style()
    {
    return ‘
    #imgbrowz0r .img-thumbnail a,
    #imgbrowz0r .img-directory a { display: block;margin: 0 auto;width: ‘.$this->config[‘max_thumb_width’].’px }

    #imgbrowz0r .img-thumbnail,
    #imgbrowz0r .img-directory { float: left;padding: 1.5em 0;width: ‘.(round(100 / $this->config[‘max_thumb_row’], 2)).’%;text-align: center }
    #imgbrowz0r .img-column-1 { clear: left }

    #imgbrowz0r .img-directory a:link,
    #imgbrowz0r .img-directory a:visited { height: ‘.($this->config[‘max_thumb_width’] * 0.8).’px;line-height: ‘.($this->config[‘max_thumb_width’] * 0.8 – 10).’px }

    /* http://sonspring.com/journal/clearing-floats */
    html body div.clear,
    html body span.clear { background: none;border: 0;clear: both;display: block;float: none;font-size: 0;list-style: none;
    margin: 0;padding: 0;overflow: hidden;visibility: hidden;width: 0;height: 0 }
    ‘;
    }

    // Generate breadcrumbs
    private function breadcrumbs()
    {
    $path_parts = $this->cur_directory !== false ? explode(‘/’, trim($this->cur_directory, ‘/’)) : array();
    $count_path = count($path_parts);

    if ($count_path > 0)
    for ($x=0; $x < $count_path; ++$x) $output[] = '‘.$path_parts[$x].’‘;

    return ‘config[‘main_url’]).'”>root‘.(isset($output) ? ‘ / ‘.implode(‘ / ‘, $output) : null);
    }

    // Generate page navigation
    private function pagination($page_count)
    {
    $cur_dir = $this->cur_directory !== false ? trim($this->cur_directory, ‘/’) : 0;

    // Previous and next links
    $prev = $this->cur_page > 1 ? ‘cur_page – 1), $this->config[‘main_url’]).'”>«‘ : null;
    $next = $this->cur_page < $page_count ? 'cur_page + 1), $this->config[‘main_url’]).'”>»‘ : null;

    // First and last page
    $first = $this->cur_page === 1 ? ‘1‘ : ‘config[‘main_url’]).'”>1‘;
    $last = $this->cur_page === $page_count ? ‘‘.$page_count.’‘ : ‘config[‘main_url’]).'”>’.$page_count.’‘;

    // Other pages
    if ($page_count > 5)
    {
    $start = $this->cur_page – 2 > 2 ? $this->cur_page – 2 : 2;
    $end = $this->cur_page + 2 < $page_count - 1 ? $this->cur_page + 2 : $page_count-1;
    if ($this->cur_page === 1) $end += 2;

    for ($x=$start; $x <= $end; ++$x) if ($this->cur_page !== $x)
    $pages[] = ‘config[‘main_url’]).'”>’.$x.’‘;
    else
    $pages[] = ‘‘.$x.’‘;
    }
    else
    {
    $end = $page_count – 1;
    for ($x=2; $x <= $end; ++$x) if ($this->cur_page !== $x)
    $pages[] = ‘config[‘main_url’]).'”>’.$x.’‘;
    else
    $pages[] = ‘‘.$x.’‘;
    }

    return $prev.’ ‘.$first.($this->cur_page > 4 ? ‘ … ‘ : ‘ ‘).implode(‘ ‘, $pages).($this->cur_page < $page_count - 3 ? ' ... ' : ' ').$last.' '.$next; } // The legendary thumbnail generater private function make_thumb($image_dir, $image_name, $image_thumbnail) { //Check if thumb dir exists if (is_writable($this->config[‘cache_dir’]) && !is_dir($this->config[‘cache_dir’]))
    exit(‘Cache directory does not exist or is not writable!’);

    $image_dir = $image_dir !== false ? $image_dir.’/’ : null;

    // Get image information
    $image_info = $this->get_image_info($this->config[‘images_dir’].’/’.$image_dir.’/’.$image_name);

    // Check if file is an supported image type
    if (!in_array($image_info[‘extension’], array(‘gif’, ‘jpg’, ‘jpeg’, ‘jpe’, ‘jif’, ‘jfif’, ‘jfi’, ‘png’)))
    return false;

    // Open the image so we can make a thumbnail
    if ($image_info[‘type’] == 3)
    $image = imagecreatefrompng($this->config[‘images_dir’].’/’.$image_dir.$image_name);
    else if ($image_info[‘type’] == 2)
    $image = imagecreatefromjpeg($this->config[‘images_dir’].’/’.$image_dir.’/’.$image_name);
    else if ($image_info[‘type’] == 1)
    $image = imagecreatefromgif($this->config[‘images_dir’].’/’.$image_dir.’/’.$image_name);
    else
    return false;

    // Calculate new width and height
    $zoomw = $image_info[‘width’] / 200;
    $zoomh = $image_info[‘height’] / 200;

    $zoom = ($zoomw > $zoomh) ? $zoomw : $zoomh;

    if ($image_info[‘width’] < 200 && $image_info['height'] < 200) { $thumb_width = $image_info['width']; $thumb_height = $image_info['height']; } else { $thumb_width = $image_info['width'] / $zoom; $thumb_height = $image_info['height'] / $zoom; } // Create an image for the thumbnail $thumbnail = imagecreatetruecolor($thumb_width, $thumb_height); // Preserve transparency in PNG and GIF images if ($image_info['type'] === 3) { $alpha_color = imagecolorallocatealpha($thumbnail, 0, 0, 0, 127); imagefill($thumbnail, 0, 0, $alpha_color); imagesavealpha($thumbnail, true); } else if ($image_info['type'] === 1 && ($transparent_index = imagecolortransparent($image)) >= 0)
    {
    $transparent_color = imagecolorsforindex($image, $transparent_index);
    $transparent_index = imagecolorallocate($thumbnail, $transparent_color[‘red’], $transparent_color[‘green’], $transparent_color[‘blue’]);
    imagefill($thumbnail, 0, 0, $transparent_index);
    imagecolortransparent($thumbnail, $transparent_index);
    }

    // Copy and resize image
    imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $image_info[‘width’], $image_info[‘height’]);

    // Save the thumbnail, but first check what kind of file it is
    if ($image_info[‘type’] == 3)
    imagepng($thumbnail, $this->config[‘cache_dir’].’/’.$image_thumbnail);
    else if ($image_info[‘type’] == 2)
    imagejpeg($thumbnail, $this->config[‘cache_dir’].’/’.$image_thumbnail, 85);
    else if ($image_info[‘type’] == 1)
    {
    imagetruecolortopalette($thumbnail, true, 256);
    imagegif($thumbnail, $this->config[‘cache_dir’].’/’.$image_thumbnail);
    }

    // Destroy
    imagedestroy($thumbnail);
    }

    // Format unix timestamp to a human readable date
    private function format_time($timestamp)
    {
    return gmdate($this->config[‘time_format’], ($timestamp + $this->config[‘time_zone’] * 3600));
    }

    // Get info from image (width, height, type, extension)
    private function get_image_info($filepath)
    {
    $getimagesize = getimagesize($filepath);

    return array(‘width’ => $getimagesize[0], ‘height’ => $getimagesize[1], ‘type’ => $getimagesize[2], ‘extension’ => $this->get_ext($filepath));
    }

    // Get extension from filename (returns the extension without the dot)
    private function get_ext($file_name)
    {
    return strtolower(substr($file_name, strrpos($file_name, ‘.’)+1));
    }
    }

    ?>

    i’m using a a folder nameed test obviously and as per the screencast 64 have set up folders, cache, css, images, gallery, inc, js, the imgbrowz0r php file is located in "inc" and I have loaded 4 random images of my desk top into the "gallery".

    The fatal error is in line $gallery->init();

    which I understand loads an object? The only thing I can summise is the the imgbrowz0r php code is different in Chris version to that I’ve downloaded – I can’t for example see any random function in this version!

    Thanks for looking.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.