Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

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
0
headbump
Asked:
headbump
  • 6
  • 3
  • 2
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now