Page 1 of 1

Can't figure out these errors.

Posted: Sun Aug 31, 2003 11:45 am
by WebD
Hello. I keep getting these errors when executing this script and I don't know why and how to fix them.
"Parse error: parse error in e:\path.ini on line 18

Warning: Empty Delimiter in e:\explorer.php on line 29"

I also need to make explorer.php 'search engine friendly' so it is like script/something/somethingelse instead of script.php?dir=something/something else. Does anyone know how to do that?

Here are the scripts

path.ini:

Code: Select all

<?php
/*path.ini

This file sets the global variables ROOTPATH and ROOTURL
which correspond to the root directory and the URL of the server.

- ROOTPATH is typically employed in require calls and include calls
  in which no argument follow the path.
- ROOTURL is required to evaluate argumented paths used with the function readfile;

Important Note
==============
readfile can be replaced with include or require under Linux


$ROOTURL="http://theboxnet.servehttp.com/tabs"
$ROOTPATH="/tabs"
?>
explorer.php:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'config.php');
Include($phpbb_root_path . 'templates/portal_header.tpl');
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
/*This is the main file of the PHP File Explorer Project

Given a directory $dir, it scans it and displays its contents
on a per-line basis.

A matching icon is shown, and more details are shown if the directive
IsShowDetails is set to true in the explorer.cfg file

The Delte button and the Edit button are set according to the directive
$IsShowDelete and the editability of the file.

(c) 2000-2002 Crow & Co.
*/
require("./path.ini");

define("SHOW_EDIT",1);
define("HIDE_EDIT",0);

/*check access mode*/
require("explorer.cfg");

/* get the variable $dir*/
$dir=$_GET&#1111;"dir"];

/*check path security*/
require("lib/inc/security.inc");

$allowbrowse= false || !strstr($dir,basename(dirname($GLOBALS&#1111;"SCRIPT_FILENAME"])));

if($IsCheckAccess) &#123; 
	include("access.php");
&#125;

/*Load the mime type file*/
require("lib/inc/mime.inc");

/*************************************************/
function GetFileInfo($f) &#123;
/*this function feeds a structure $s with file info:
permission, owner, group, size, mtime from filename $f
*/
$s = array (	'perm'  => '',
		'humanperm' => '',	//human readable permissions: rwxrwxrwx
		'ux'    => false,	//is this file is user executable ?
		'islnk' => false,	//is this file is a link ?
		'owner'  => '',
		'group'  => '',
		'size'   => 0,
		'mtime'  => ''
		);
$mystat=stat($f);

//permissions (restrict to the last 9 bit)
$s&#1111;"perm"]=$mystat&#1111;2] & 511;

/*u+x permission for owner ( 101000000 (=320) is r-x******)
we first have to filter with 512-1 to substract 16384 from the permissions
returned by fileperms()
*/
if(($s&#1111;"perm"] & 320) == 320) $s&#1111;'ux']=true;

/*convert the permissions to human readable perms*/
$fullperms=256; // rwxrwxrwx
$s&#1111;"humanperm"]="";
$let = array('r','x','w'); //no, it's not rwx, but rxw, because browsed backwards

for($i=9;$i>0;$i--) &#123; 
	($s&#1111;"perm"] & $fullperms)? $s&#1111;"humanperm"].=$let&#1111;$i % 3]:$s&#1111;"humanperm"].="-";
	$fullperms = $fullperms >> 1;
&#125;
//is it a link?
if(!strcmp(filetype($f),"link")) $s&#1111;'islnk']=true;

/*//owner
$s&#1111;"owner"]=$mystat&#1111;4];

//group
$s&#1111;"group"]=$mystat&#1111;5];

//size in b
$s&#1111;"size"]=$mystat&#1111;7];

//last modification date
$s&#1111;"mtime"]=date('Y M d H:s',$mystat&#1111;10]);*/

return($s);
&#125;
/*
/*************************************************/
?>
<html>

<head>
<title></title>
<link rel=stylesheet href="lib/explorer.css" type="text/css">
<script language=JavaScript src="lib/more.js"></script>
</head>

<body bgcolor=white>

<table border=0 cellspacing=3 width=700>
  <tr>
    <td colspan=2>
	<div class=title1>
	<img src="images/explorer.gif" border=0>
	File Explorer</div>
	<br>
    </td>
  </tr>
</table>
<?php
/*if path exists, open it!*/
$hDir=opendir($ROOTPATH.$dir);

/*output the current path*/
print "<div class=title2>\n";

if($allowbrowse) &#123;
	//print "Contents of ".$dir;
	//if(strcmp($dir,'/')) print "/";
&#125;
print "</div>\n";

/*browse dir*/
$j=0;
$frmid=0;

//browse all the dirs + files of the current folder
//prepare the exceptions (file to hide)
if(strlen($Exceptions)>0) $except=explode(",",$Exceptions);

while ($file=readdir($hDir)) &#123;
	$res=true;
	if(strlen($Exceptions)>0) &#123;
		reset($except);
		for($i=0;$i<count($except);$i++) &#123;
			if(!strcmp($file,$except&#1111;$i])) &#123;
				$res=false;
				break;
			&#125;
		&#125;
	&#125;
	//is the file to be displayed
	if($res) &#123;
		$files&#1111;$j++]=$file;
	&#125;
&#125; /*end while*/

/*updir link*/
if($allowbrowse) &#123;
	if(strcmp($dir,"/")) 	&#123;
		$updir=dirname($dir);
		$updir=str_replace("&quote;,"/",$updir);
		
		if($updir=="")
			$updir="/";
	
		/*print "<div class=normal><a href='explorer.php?dir=$updir'><img src='images/updir.gif' border=0 alt='updir' width=16 height=16></a></div>\n";*/
	&#125;

	/*sort files if some*/
	if(count($files)) &#123;
		sort($files);
		reset($files);
	
		/*format contents of dir into a table*/
		
		
		print "<table border=0 width=";
		($IsShowDetails)? print "700" : print "288";
		print " class=normal>\n";
	
		/*print headers*/
		print "  <tr>\n";
		print "    <td class=bdyResult0 width=200><b>name</b></td>\n";
		
		//show details ?
		if($IsShowDetails) &#123;
			//print "    <td class=bdyResult0 width=60 height=10 align=right><b>Rate1</b></td>\n";
			print "    <td class=bdyResult0 width=20 height=15 align=center><b>Rate</b></td>\n";
			print "    <td class=bdyResult0 width=40 height=15 align=center><b>Add To Cart</b></td>\n";

		&#125;
		
	
	
		//number of items
		$i=0;
		while (list($key,$name) = each($files)) &#123;
			
			//what kind of class do we have for this line #i
			$class= "bdyResult".($i%2);
			
			$filename=$ROOTPATH."$dir$sp$name";
			$rc=chkfile($name,$icon);
	
			//is the current file is a directory ?
			if(is_dir($filename)) &#123;
				$filestats=GetFileInfo($filename);
	
				/*if the dir has not the u+x permission or the dir is explorer, notice it*/
				if(!$filestats&#1111;'ux'] || !$AllowSelfBrowse && !strcmp($name,basename(dirname($GLOBALS&#1111;"SCRIPT_FILENAME"]))) ) &#123;
					// display name
					print "  <tr>\n";
					print "    <td class=$class width=240>\n";
					print "\t<img border=0 src='images/icon_nodir.gif' alt='&#1111;private dir]' width=16 height=16>&nbsp;$name\n";
					print "    </td>\n";
				&#125;
				else &#123;
					// display name
					print "  <tr>\n";
					print "    <td class=$class width=240>\n";

					$href="explorer.php?dir=$dir$sp$name";
					/*print "\t<a href="".$href."">
<img border=0 width=16 height=16 ";
					if($filestats&#1111;'islnk'])
						print "src='images/icon_dirlnk.gif' alt='&#1111;dir link]'></a>";
					else
						print "src='images/icon_dir.gif' alt='&#1111;dir]'>
</a>";*/
						
					print "&nbsp;<a href="".$href."">$name</a>\n";
					print "    </td>\n";
				&#125;		
	
				//show details ?
				if($IsShowDetails) &#123;
					//display permissions
					print "    <td class=$class width=60 height=10 align=right>";
					print "";
					print "</td>\n";
		
					//display owner's name
					print "    <td class=$class width=50 height=15 align=center>";
					print "";
					print "</td>\n";
		
	

					print "</td>\n";
					print "  </tr>\n";			
					
					$i++;
				&#125;
			&#125;
		&#125;
		
		reset($files);
		while (list($key,$name) = each($files)) &#123;
		
			$rc=chkfile($name,$icon);
				
			/*the output format is:
			<permissions> <owner> <group> <size> <last modified time> <name>*/
			$filename=$ROOTPATH."$dir$sp$name";
			$href=$ROOTURL."$dir$sp$name";
	
			if(!is_dir($filename)) &#123;
	
				//what kind of class do we have for this line #i
				$class= "bdyResult".($i%2);
	
				$filestats=GetFileInfo($filename);
				
				print "  <tr>\n";
				print "    <td class=$class width=240 height=10 valign=middle>\n";
				print "\t<a href="".$href.""></a>";
				print "&nbsp;<a href="".$href."">$name</a>\n";
				print "    </td>\n";
	
				//show details ?
				if($IsShowDetails) &#123;			
					//display permissions
					print "    <td class=$class width=20 height=10 align=right>";
					print "<a href="MyAccount.php?op=rate&f=$name">Rate</a>";
					print "</td>\n";
		
					//display owner's name
					print "    <td class=$class width=40 height=15 align=center>";
					print "Disabled";
					print "</td>\n";
		
					//display group's name

					print "</td>\n";
				&#125;
				
	
			$i++;
			&#125;
		&#125; //end of while
		
	print "</table>\n\n";
	
	//print number of items in this directory
	$msg=$i." item";
	if($i>1) $msg.="s";
	print "<div class=comment>$msg.</div>\n";
	
	&#125; //end of if(count($files))
	
	else &#123;
		print "<br><div class=normal>&#1111;Empty]</div>\n";
	&#125;
	
	
&#125; //endif allowbrowse

else &#123;
	if(! $pass++) &#123;
	print "  <div class=error>browsing under the explorer itself is forbidden (see your administrator)</div>\n";
	&#125;
&#125;

?>
<?
Include($phpbb_root_path . 'templates/portal_copyright.tpl');
Include($phpbb_root_path . 'templates/portal_footer.tpl');
</body>
</html>
Any help would be greatly appreciated!

Posted: Sun Aug 31, 2003 11:51 am
by m3rajk
the seoncd one is long. gimme a sec. the first one is obvious to me. none of the lines are ended.


you have the end each line wirh ;


gimme a moment to look over the the other one.

Posted: Sun Aug 31, 2003 11:54 am
by WebD
oh, right, oops. ok, thnx. Now all I need is the 'search engine friendly' code, can anyone do that?

Re: Can't figure out these errors.

Posted: Sun Aug 31, 2003 11:57 am
by m3rajk
1: aside
this place has a php tag which is MUCH nicer for php than code. the fact you're using one of them is great, if you can use php when doing php that'd be better

2: errors
first one: you needed to end each line (;) and end the comment (*/)

second one: can't figure out. line 29 is */ in what you posted. something's not quite adding up
WebD wrote:Here are the (fixed?) scripts

path.ini:

Code: Select all

<?php
/*path.ini

This file sets the global variables ROOTPATH and ROOTURL
which correspond to the root directory and the URL of the server.

- ROOTPATH is typically employed in require calls and include calls
  in which no argument follow the path.
- ROOTURL is required to evaluate argumented paths used with the function readfile;

Important Note
==============
readfile can be replaced with include or require under Linux
*/

$ROOTURL="http://theboxnet.servehttp.com/tabs";
$ROOTPATH="/tabs";
?>
explorer.php:

Code: Select all

&lt;?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'config.php');
Include($phpbb_root_path . 'templates/portal_header.tpl');
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
/*This is the main file of the PHP File Explorer Project

Given a directory $dir, it scans it and displays its contents
on a per-line basis.

A matching icon is shown, and more details are shown if the directive
IsShowDetails is set to true in the explorer.cfg file

The Delte button and the Edit button are set according to the directive
$IsShowDelete and the editability of the file.

(c) 2000-2002 Crow &amp; Co.
*/
require("./path.ini");

define("SHOW_EDIT",1);
define("HIDE_EDIT",0);

/*check access mode*/
require("explorer.cfg");

/* get the variable $dir*/
$dir=$_GET&#1111;"dir"];

/*check path security*/
require("lib/inc/security.inc");

$allowbrowse= false || !strstr($dir,basename(dirname($GLOBALS&#1111;"SCRIPT_FILENAME"])));

if($IsCheckAccess) &#123; 
	include("access.php");
&#125;

/*Load the mime type file*/
require("lib/inc/mime.inc");

/*************************************************/
function GetFileInfo($f) &#123;
/*this function feeds a structure $s with file info:
permission, owner, group, size, mtime from filename $f
*/
$s = array (	'perm'  =&gt; '',
		'humanperm' =&gt; '',	//human readable permissions: rwxrwxrwx
		'ux'    =&gt; false,	//is this file is user executable ?
		'islnk' =&gt; false,	//is this file is a link ?
		'owner'  =&gt; '',
		'group'  =&gt; '',
		'size'   =&gt; 0,
		'mtime'  =&gt; ''
		);
$mystat=stat($f);

//permissions (restrict to the last 9 bit)
$s&#1111;"perm"]=$mystat&#1111;2] &amp; 511;

/*u+x permission for owner ( 101000000 (=320) is r-x******)
we first have to filter with 512-1 to substract 16384 from the permissions
returned by fileperms()
*/
if(($s&#1111;"perm"] &amp; 320) == 320) $s&#1111;'ux']=true;

/*convert the permissions to human readable perms*/
$fullperms=256; // rwxrwxrwx
$s&#1111;"humanperm"]="";
$let = array('r','x','w'); //no, it's not rwx, but rxw, because browsed backwards

for($i=9;$i&gt;0;$i--) &#123; 
	($s&#1111;"perm"] &amp; $fullperms)? $s&#1111;"humanperm"].=$let&#1111;$i % 3]:$s&#1111;"humanperm"].="-";
	$fullperms = $fullperms &gt;&gt; 1;
&#125;
//is it a link?
if(!strcmp(filetype($f),"link")) $s&#1111;'islnk']=true;

/*//owner
$s&#1111;"owner"]=$mystat&#1111;4];

//group
$s&#1111;"group"]=$mystat&#1111;5];

//size in b
$s&#1111;"size"]=$mystat&#1111;7];

//last modification date
$s&#1111;"mtime"]=date('Y M d H:s',$mystat&#1111;10]);*/

return($s);
&#125;
/*
/*************************************************/
?&gt;
&lt;html&gt;

&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;link rel=stylesheet href="lib/explorer.css" type="text/css"&gt;
&lt;script language=JavaScript src="lib/more.js"&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body bgcolor=white&gt;

&lt;table border=0 cellspacing=3 width=700&gt;
  &lt;tr&gt;
    &lt;td colspan=2&gt;
	&lt;div class=title1&gt;
	&lt;img src="images/explorer.gif" border=0&gt;
	File Explorer&lt;/div&gt;
	&lt;br&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;?php
/*if path exists, open it!*/
$hDir=opendir($ROOTPATH.$dir);

/*output the current path*/
print "&lt;div class=title2&gt;\n";

if($allowbrowse) &#123;
	//print "Contents of ".$dir;
	//if(strcmp($dir,'/')) print "/";
&#125;
print "&lt;/div&gt;\n";

/*browse dir*/
$j=0;
$frmid=0;

//browse all the dirs + files of the current folder
//prepare the exceptions (file to hide)
if(strlen($Exceptions)&gt;0) $except=explode(",",$Exceptions);

while ($file=readdir($hDir)) &#123;
	$res=true;
	if(strlen($Exceptions)&gt;0) &#123;
		reset($except);
		for($i=0;$i&lt;count($except);$i++) &#123;
			if(!strcmp($file,$except&#1111;$i])) &#123;
				$res=false;
				break;
			&#125;
		&#125;
	&#125;
	//is the file to be displayed
	if($res) &#123;
		$files&#1111;$j++]=$file;
	&#125;
&#125; /*end while*/

/*updir link*/
if($allowbrowse) &#123;
	if(strcmp($dir,"/")) 	&#123;
		$updir=dirname($dir);
		$updir=str_replace("&quote;,"/",$updir);
		
		if($updir=="")
			$updir="/";
	
		/*print "&lt;div class=normal&gt;&lt;a href='explorer.php?dir=$updir'&gt;&lt;img src='images/updir.gif' border=0 alt='updir' width=16 height=16&gt;&lt;/a&gt;&lt;/div&gt;\n";*/
	&#125;

	/*sort files if some*/
	if(count($files)) &#123;
		sort($files);
		reset($files);
	
		/*format contents of dir into a table*/
		
		
		print "&lt;table border=0 width=";
		($IsShowDetails)? print "700" : print "288";
		print " class=normal&gt;\n";
	
		/*print headers*/
		print "  &lt;tr&gt;\n";
		print "    &lt;td class=bdyResult0 width=200&gt;&lt;b&gt;name&lt;/b&gt;&lt;/td&gt;\n";
		
		//show details ?
		if($IsShowDetails) &#123;
			//print "    &lt;td class=bdyResult0 width=60 height=10 align=right&gt;&lt;b&gt;Rate1&lt;/b&gt;&lt;/td&gt;\n";
			print "    &lt;td class=bdyResult0 width=20 height=15 align=center&gt;&lt;b&gt;Rate&lt;/b&gt;&lt;/td&gt;\n";
			print "    &lt;td class=bdyResult0 width=40 height=15 align=center&gt;&lt;b&gt;Add To Cart&lt;/b&gt;&lt;/td&gt;\n";

		&#125;
		
	
	
		//number of items
		$i=0;
		while (list($key,$name) = each($files)) &#123;
			
			//what kind of class do we have for this line #i
			$class= "bdyResult".($i%2);
			
			$filename=$ROOTPATH."$dir$sp$name";
			$rc=chkfile($name,$icon);
	
			//is the current file is a directory ?
			if(is_dir($filename)) &#123;
				$filestats=GetFileInfo($filename);
	
				/*if the dir has not the u+x permission or the dir is explorer, notice it*/
				if(!$filestats&#1111;'ux'] || !$AllowSelfBrowse &amp;&amp; !strcmp($name,basename(dirname($GLOBALS&#1111;"SCRIPT_FILENAME"]))) ) &#123;
					// display name
					print "  &lt;tr&gt;\n";
					print "    &lt;td class=$class width=240&gt;\n";
					print "\t&lt;img border=0 src='images/icon_nodir.gif' alt='&#1111;private dir]' width=16 height=16&gt;&amp;nbsp;$name\n";
					print "    &lt;/td&gt;\n";
				&#125;
				else &#123;
					// display name
					print "  &lt;tr&gt;\n";
					print "    &lt;td class=$class width=240&gt;\n";

					$href="explorer.php?dir=$dir$sp$name";
					/*print "\t&lt;a href="".$href.""&gt;
&lt;img border=0 width=16 height=16 ";
					if($filestats&#1111;'islnk'])
						print "src='images/icon_dirlnk.gif' alt='&#1111;dir link]'&gt;&lt;/a&gt;";
					else
						print "src='images/icon_dir.gif' alt='&#1111;dir]'&gt;
&lt;/a&gt;";*/
						
					print "&amp;nbsp;&lt;a href="".$href.""&gt;$name&lt;/a&gt;\n";
					print "    &lt;/td&gt;\n";
				&#125;		
	
				//show details ?
				if($IsShowDetails) &#123;
					//display permissions
					print "    &lt;td class=$class width=60 height=10 align=right&gt;";
					print "";
					print "&lt;/td&gt;\n";
		
					//display owner's name
					print "    &lt;td class=$class width=50 height=15 align=center&gt;";
					print "";
					print "&lt;/td&gt;\n";
		
	

					print "&lt;/td&gt;\n";
					print "  &lt;/tr&gt;\n";			
					
					$i++;
				&#125;
			&#125;
		&#125;
		
		reset($files);
		while (list($key,$name) = each($files)) &#123;
		
			$rc=chkfile($name,$icon);
				
			/*the output format is:
			&lt;permissions&gt; &lt;owner&gt; &lt;group&gt; &lt;size&gt; &lt;last modified time&gt; &lt;name&gt;*/
			$filename=$ROOTPATH."$dir$sp$name";
			$href=$ROOTURL."$dir$sp$name";
	
			if(!is_dir($filename)) &#123;
	
				//what kind of class do we have for this line #i
				$class= "bdyResult".($i%2);
	
				$filestats=GetFileInfo($filename);
				
				print "  &lt;tr&gt;\n";
				print "    &lt;td class=$class width=240 height=10 valign=middle&gt;\n";
				print "\t&lt;a href="".$href.""&gt;&lt;/a&gt;";
				print "&amp;nbsp;&lt;a href="".$href.""&gt;$name&lt;/a&gt;\n";
				print "    &lt;/td&gt;\n";
	
				//show details ?
				if($IsShowDetails) &#123;			
					//display permissions
					print "    &lt;td class=$class width=20 height=10 align=right&gt;";
					print "&lt;a href="MyAccount.php?op=rate&amp;f=$name"&gt;Rate&lt;/a&gt;";
					print "&lt;/td&gt;\n";
		
					//display owner's name
					print "    &lt;td class=$class width=40 height=15 align=center&gt;";
					print "Disabled";
					print "&lt;/td&gt;\n";
		
					//display group's name

					print "&lt;/td&gt;\n";
				&#125;
				
	
			$i++;
			&#125;
		&#125; //end of while
		
	print "&lt;/table&gt;\n\n";
	
	//print number of items in this directory
	$msg=$i." item";
	if($i&gt;1) $msg.="s";
	print "&lt;div class=comment&gt;$msg.&lt;/div&gt;\n";
	
	&#125; //end of if(count($files))
	
	else &#123;
		print "&lt;br&gt;&lt;div class=normal&gt;&#1111;Empty]&lt;/div&gt;\n";
	&#125;
	
	
&#125; //endif allowbrowse

else &#123;
	if(! $pass++) &#123;
	print "  &lt;div class=error&gt;browsing under the explorer itself is forbidden (see your administrator)&lt;/div&gt;\n";
	&#125;
&#125;

?&gt;
&lt;?
Include($phpbb_root_path . 'templates/portal_copyright.tpl');
Include($phpbb_root_path . 'templates/portal_footer.tpl');
&lt;/body&gt;
&lt;/html&gt;
Any help would be greatly appreciated!

Posted: Sun Aug 31, 2003 12:42 pm
by WebD
hey, thanks, Yeah I missed the ; (oops). I didn't notice the php tag, I'll use that next time, it is alot better than the code tag. Yeah exactly, something isn't adding up - that is why I posted, can't figure out what the problem is. Also, does anyone know how to do the 'search engine friendly' urls? (explained on my first post)