Script error

Hey all,

I downloaded this script that I'm attempting to get to work and am running into problems...I'm not sure what's going on...here's the script and then it will be followed by the error:


--
<?php
/*
photo_index.php
-----------------------------------------------------------------------------------------------------
This is a very simple script to generate a 'preview' of a directory of
images.  It will ignore
any files which aren't .gif, .jpg, .jpeg, or .png.  Basically it will
generate an HTML page with
a textbox of BBCode (for posting on forums) and the <img> itself so you
can preview it.  Saves
a lot of time when you would normally be looking at a regular directory
index and clicking back
and forth!

I recommend you place this file in your favorite includes/ folder or the
root of your website, and
call it using the php include() function.  That way should you find a
need to modify this file, it's
centrally located in one spot. ;)

** WHATEVER YOU DO...
** This file (or the file which will include() this file) needs to be
named index.php
** Then you place the index.php file in the directory you wish to view.
** That's really it.

I wrote this on a whim so feel free to clean it up, change it,
distribute, whatever.

Email me if you have any questions or suggestions... webguy at 330i dot net

-Chris
-----------------------------------------------------------------------------------------------------
*/

// modify this to reflect your server's domain name.
// NOTE: format is protocol://domain_name with NO trailing slash.
$root_server_url = "http://images.330i.net";

// ** ** ** **        No need to modify beyond this line        ** ** ** **

// if the request wasn't for the index.php page directly, redirect the
client
if(!strpos($_SERVER['REQUEST_URI'], "index.php")){
      header("location: index.php");
}

// for each file in the directory...
$dir_name = "./";
$myfiles=GetDirContents(dirname($dir_name));

for($i=0; $i<count($myfiles); $i++){
      $num = $i+1;                                                // file number increment
      $stroutput = showFile($myfiles[$i]);            // either get formatted output
for the file, or a false
      echo "<b>" . $num . ".</b> ";

      if($stroutput){
            echo $stroutput;
      }else{
            echo "File skipped; not gif, png nor jpg.";
      }
}
?>

<?php
// GetDirContents(mapped_directory)
// Thanks to andy.at.azengel.dot.com for this function, found at
// http://php.mirrors.ilisys.com.au/manual/en/ref.dir.php
//
// This function returns an array of filenames (with the directory
appended) which we
// use in a loop.
function GetDirContents($dir){
      ini_set("max_execution_time", 10);
      if (!is_dir($dir)){die ("Error!");}                                                                        // is it a directory?
      if ($root=@opendir($dir)){
            while ($file=readdir($root)){
                  if($file=="." || $file==".."){continue;}
                  if(is_dir($dir."/".$file)){
                        $files=array_merge($files,GetDirContents($dir."/".$file));
                  }else{
                        $files[]=$dir."/".$file;
                  }
            }
      }

      return $files;            // array of dir+filenames
}

// showfile(filename)
// returns HTML to be output'd to the client
// (alter to suit your needs)
function showFile($filename){
      if(strpos(strtolower($filename), ".gif") ||
strpos(strtolower($filename), ".jpg" || strpos(strtolower($filename),
".jpeg") || strpos(strtolower($filename), ".png"){
            $filename = makeurl($filename);
            return "<input type='text' style='width: 600px; font-size: 8pt;'
value='[img]" . $filename . "[/img]' onClick='this.select();'><br><img
style='margin-top: 5px;' src='" . $filename . "'><hr size=1><br>";
      }else{
            return false;
      }
}

// changes our relative pathing to a fully qualified URL for bbcode purposes
function makeurl($relative_path) {
      global $dir_name, $root_server_url;
      return $root_server_url . str_replace("index.php",
str_replace($dir_name, "", $relative_path), $_SERVER["REQUEST_URI"]);
}
?>



Error:
Parse error: syntax error, unexpected '{' in D:\hshome\copyking\copy-king.com\testblog\index.php on line 93
 Line 93 is:
      if(strpos(strtolower($filename), ".gif") || strpos(strtolower($filename), ".jpg" || strpos(strtolower($filename), ".jpeg") || strpos(strtolower($filename), ".png"){

Any ideas?

thx,
A
headbumpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TomeeboyCommented:
You're missing a paranthesis:

   if(strpos(strtolower($filename), ".gif") || strpos(strtolower($filename), ".jpg" || strpos(strtolower($filename), ".jpeg") || strpos(strtolower($filename), ".png")){
0
RoonaanCommented:
You have to add a ) just in front of the curly { :

if(strpos(strtolower($filename), ".gif") || strpos(strtolower($filename), ".jpg" || strpos(strtolower($filename), ".jpeg") || strpos(strtolower($filename), ".png")) {

-r-
0
TomeeboyCommented:
BTW, what I posted is the fixed version of the line (added the missing parathesis right before the { ).

Hope that helps!
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

RoonaanCommented:
To make live easier and also support PNG, PnG, Png, pnG, and all types of capitals and lowercase, you can also use:

if(preg_match('/\.(gif|jpg|jpeg|png)/i', $filename)) {

-r-
0
headbumpAuthor Commented:
Hello again all,

I'm still getting the same error:

Parse error: syntax error, unexpected '{' in D:\hshome\copyking\copy-king.com\testblog\index.php on line 93


after fixing the line with an additional ")"

thx,
A
0
TomeeboyCommented:
  if(strpos(strtolower($filename), ".gif") || strpos(strtolower($filename), ".jpg") || strpos(strtolower($filename), ".jpeg") || strpos(strtolower($filename), ".png")){

Sorry was another one missing in the same statement.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
headbumpAuthor Commented:
Thanks, this fixes the problem, but on a related note, any idea why the page just keeps loading and reloading now?

http://www.copy-king.com/testblog/index.php

thx,
A
0
TomeeboyCommented:
Hm.. doesn't seem to be loading for me at all.. perhaps it is stuck in an infinite loop or something.  Looking to see if I can find anything in the code you posted above...
0
TomeeboyCommented:
The only thing I see in the above code that looks like it could potentially cause a continuous reload of the page is this:

if(!strpos($_SERVER['REQUEST_URI'], "index.php")){
     header("location: index.php");
}

Try commenting that out and see if it makes any difference.
0
headbumpAuthor Commented:
Will do, and thanks for the quick solution.

A
0
TomeeboyCommented:
No problem, hope it helps.  If that line I suggested commenting out is causing the problem, you can echo $_SERVER['REQUEST_URI'] to see what is being returned.  Maybe something isn't matching up correctly.  You might also see what value is being returned for strpos(), as it's possible for strpos to return a non-boolean value that is considered false:

http://us3.php.net/manual/en/function.strpos.php
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.