treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Parse Error installing #64 Building a Photo Gallery

  • I'm tiring to install the photo gallery that is featured on this site (#64 Building a Photo Gallery). I have all my folders and directories setup, my imgbrowz0r.php is in the inc folder, but when I try to view the page I get this message.

    ------------------------------------
    Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/shepa0/public_html/chris/imgbrowz0r/inc/imgbrowz0r.php on line 37

    Fatal error: Cannot instantiate non-existent class: imgbrowz0r in /home/shepa0/public_html/chris/imgbrowz0r/index.php on line 65

    -----------------------------------

    First off there is nothing on line 37.
    Second this is what is on like 65: $gallery = new imgbrowz0r($config);

    Here is a link to the live page:
    http://shepardsuperteam.com/chris/imgbrowz0r/index.php

    And hers my code. Please let me know If I have anything out of place.
    ----------------------------------
    <?php

    error_reporting(E_ALL);

    // Some stuff for generating stats
    function file_size($size)
    {
    $units = array('b', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb');

    for ($i = 0; $size > 1024; $i++)
    $size /= 1024;

    return round($size, 2).' '.$units[$i];
    }

    function get_microtime($microtime=false)
    {
    if ($microtime === false)
    $microtime = microtime();

    list($usec, $sec) = explode(' ', $microtime);
    return ((float)$usec + (float)$sec);
    }

    $start_timer = microtime();

    // Include class
    require 'http://shepardsuperteam.com/chris/imgbrowz0r/inc/imgbrowz0r.php';

    // These are all settings (set to default). The settings are not validated since you have to configure everything.
    // There is a chance that ImgBrowz0r stops working if you enter the wrong values.
    $config = array(
    // Directory settings. These are required. Without trailing slash. (required)
    'images_dir' => 'http://shepardsuperteam.com/chris/imgbrowz0r/gallery',
    'cache_dir' => 'http://shepardsuperteam.com/chris/imgbrowz0r/cache',


    'main_url' => 'http://shepardsuperteam.com/chris/imgbrowz0r/index.php',
    'images_url' => 'http://shepardsuperteam.com/chris/imgbrowz0r/images',
    'cache_url' => 'http://shepardsuperteam.com/chris/imgbrowz0r/cache',

    // Sorting settings (optional)
    'sort_by' => 3, // 1 = filename, 2 = extension (png, gif, etc.), 3 = inode change time of file
    'sort_order' => false, // true = ascending, false = descending

    // Thumbnail settings (optional)
    'thumbs_per_page' => 12, // Amount of thumbnails per page
    'max_thumb_row' => 4, // Amount of thumbnails on a row
    'max_thumb_width' => 200, // Maximum width of thumbnail
    'max_thumb_height' => 200, // Maximum height of thumbnail

    // Time settings (optional)
    'time_format' => 'F jS, Y', // Date formatting. Look at the PHP date() for help: http://nl3.php.net/manual/en/function.date.php
    'time_zone' => 0, // Timezone. Example: 1
    'enable_dst' => false, // Daylight saving time (DST). Set this to true to enable it.

    // Misc settings (optional)
    'ignore_port' => false, // Ignore port in url. Set this to true to ignore the port.
    'dir_thumbs' => true, // Show a thumbnail in a category box. Default is false.
    'random_thumbs' => false, // Use random thumbnails for categories. Default is false.
    'read_thumb_limit' => 0 // See README for information about this setting.
    );

    // Start the class
    $gallery = new imgbrowz0r($config);

    // XHTML stuff
    ?><!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
    <html xmlns=\"http://www.w3.org/1999/xhtml\">
    <head>
    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />

    <title>ImgBrowz0r 0.3-dev</title>

    <style type=\"text/css\">
    body { padding: 0;margin:0;text-align: center;font-size:90%;line-height: 1.5;background-color: #fff;font-family: Tahoma, Verdana, sans-serif }

    a:link, a:visited { color: #F52542;text-decoration: underline }
    a:hover, a:active { color: #333 }
    strong { font-weight: bold }

    /* This is some example CSS. You can change this to your own liking. */
    .imgbrowz0r-navigation, #imgbrowz0r { margin: 0 auto;width: 970px;text-align: left }
    .imgbrowz0r-navigation { padding: 1.5em 0 0.5em }
    .imgbrowz0r-navigation .img-statistics { margin-top: 1.5em }

    #imgbrowz0r .img-row { padding: 0 1em }
    #imgbrowz0r .img-directory a:link,
    #imgbrowz0r .img-directory a:visited { font-family: Georgia, \"Times New Roman\", Times, serif;text-decoration: none }

    #imgbrowz0r .img-thumbnail a:link img,
    #imgbrowz0r .img-thumbnail a:visited img { border: 1px solid #000 }
    #imgbrowz0r .img-thumbnail a:hover img,
    #imgbrowz0r .img-thumbnail a:active img { border-color: #F52542 }

    #imgbrowz0r .img-directory a:link,
    #imgbrowz0r .img-directory a:visited { background-color: #000;border: 1px solid #000;font-size: 1.5em;color: #ccc }
    #imgbrowz0r .img-directory a:hover,
    #imgbrowz0r .img-directory a:active { border-color: #F52542;color: #F52542 }

    #imgbrowz0r .img-directory span.img-dir-name,
    #imgbrowz0r .img-directory span.img-thumb-date { display: block }
    #imgbrowz0r .img-directory span.img-dir-name { font-weight: bold;font-size: 1.2em }

    #imgbrowz0r .img-thumbnail a,
    #imgbrowz0r .img-directory a { display: block;margin: 0 auto;width: 200px }

    #imgbrowz0r .img-thumbnail,
    #imgbrowz0r .img-directory { float: left;padding: 1.5em 0;width: 25%;text-align: center }
    #imgbrowz0r .img-column-1 { clear: left }

    #imgbrowz0r .img-directory a:link,
    #imgbrowz0r .img-directory a:visited { height: 160px;line-height: 150px;
    background-repeat: no-repeat;background-position: 50% 50% }

    /* 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 }
    </style>
    </head>
    <body>

    <?php

    // Prepare everything. This function must be called before you call other functions.
    $gallery->init();

    // Generate navigation and statistics
    $gallery_breadcrumbs = $gallery->breadcrumbs();
    $gallery_pagination = $gallery->pagination();
    $gallery_statistics = $gallery->statistics();

    // Display navigation
    echo '<div class=\"imgbrowz0r-navigation\">', \"\n\t\", $gallery_breadcrumbs, \"\n\t\", $gallery_pagination, \"\n\t\", $gallery_statistics, \"\n\", '</div>', \"\n\n\";

    // Display images and directories
    echo $gallery->browse();

    // Display navigation
    echo '<div class=\"imgbrowz0r-navigation\">', \"\n\t\", $gallery_pagination, \"\n\t\", $gallery_breadcrumbs, \"\n\", '</div>', \"\n\n\";

    // Showing some stats
    echo '<p>Processing time: ', round(get_microtime(microtime()) - get_microtime($start_timer), 5), ' &amp;&amp; Memory usage: ', file_size(memory_get_usage()), '</p>';

    ?>

    </body>
    </html>
  • Read the error messages.
    The problem is on line 37 (or before) of imgbrowz0r.php, which is why the class can't be called on line 65 of index.php.
  • Sorry, I'm still not seeing the problem. I forgot to mention this is my first time messing with anything PHP.

    I looked back on the video (#64 Building a Photo Gallery) and noticed that he had a ?q=%PATH% on the back end of his link to the main_url. I remember having that in there before but I deleted it because I thought it was junk added on from Dreamweaver, but I put it back on (that's) on line 38, so now it reads like this.

    38| 'main_url' => 'http://shepardsuperteam.com/chris/imgbrowz0r/index.php?q=%PATH%',

    line 65 still reads like this

    65|$gallery = new imgbrowz0r($config);

    Do you see anything wrong between these two codes?
  • I repeat:

    The problem is on line 37 (or before) of imgbrowz0r.php
  • The problem is on line 37 (or before) of imgbrowz0r.php

    Ok. So what do I do with this information. "imgbrowz0r.php" only shows up on line 28. Is it written wrong, directing wrong, wrong file name?

    p.s. Thanks for the help so far.
  • imgbrowz0r.php is a file in the "inc" directory.
  • Yes, I know what it is and where it's at. I just don't understand what it's saying about the file. It's in the right directory. It wasn't mirrored on my hard drive, but I fixed that with no change.

    I just fond this message in my live log on the server.

    [24-Aug-2009 06:59:52] PHP Fatal error: Cannot instantiate non-existent class: imgbrowz0r in /home/shepa0/public_html/chris/imgbrowz0r/index.php on line 65
  • Sorry but I don't know how to make it any clearer. The problem is on (or before) line 37 of imgbrowz0r.php.

    EDIT.
    Are you sure your server is running PHP5 and not PHP4?
  • They use something called suPHP. Ever heard of it?
  • Now I know what imgbrowz0r is I'm guessing that you haven't altered that file in any way? I can only surmise that suPHP is the problem. Have you tried the gallery locally using Manp or Xampp or whatever?
  • Okay. I believe my problem was the server was using PHP 4.9 and not 5. So as far as this post Its resolved.
  • Hello Friends,I have some problem regarding parsing.
    I am getting Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING error, here are the lines:
    for($i=0; $i<12; $i++){
    $aquery = "INSERT INTO uaq_scbatsmen VALUES('$row2['id']', 'a', '$a_player[$i]', '$a_out[$i]', '$a_balls[$i]', '$a_4s[$i]', '$a_6s[$i]', '$a_runs[$i]')";
    mysql_query($aquery);
    }
    The problem line is the middle one ($aquery). Most probably problem is that I am missing some " or ; or something else but after hours of head banging I still can't find the problem.
    Regards
    Jenifer
    Support executive