Page 1 of 1

opening a directory

Posted: Mon Feb 28, 2011 5:55 pm
by danwguy
So I can open a dir and list it's contents however I would like them to be, my problem/question is doing it using classes. I have a dirview-class.php that looks like this...

Code: Select all

<?php
class Dirview
{
	public function dirlist($name) {
		
			global $data
			$TrackDir=opendir($name."/");
			function filename_safe($file) {
				$temp = $file;
				$temp = str_replace("-", " ", $temp);
				
				$result = '';
				for($i=0; $i<strlen($temp); $i++) {
				if(preg_match('([0-9]|[a-z]|_)', $temp[$i])) {
				$result = $result . $temp[$i];
				}
				}
				}
							
				
				while($file = readdir($TrackDir)) {
				
				$ext = substr($file, strrpos($file, '.') + 1);
				if($file == "." || $file == ".." || $ext == "db"){}
				else {
				$temp = $file;
				
					print "<a rel='$name' href='$dir/$temp'></a>";
				}
				}
				closedir($TrackDir);
				return $data;
				}
}

?>
Then in my main viewing page I should just be able to do this..

Code: Select all

<?php 
	
include("dirview-class.php);

		$dir = new Dirview;
		$dir->dirlist('Australia');
				?>
but I keep getting ...
Parse error: syntax error, unexpected T_STRING in C:\WEB_ROOT\galleryclass.php on line 90
line 90 according to alleycode is
<!-- <a rel="australia" href="Australia/img6.jpg"> </a>
not sure how that works because I am ending my php as you can see from above. Any help on this one please

Re: opening a directory

Posted: Tue Mar 01, 2011 11:01 am
by social_experiment

Code: Select all

include("dirview-class.php);
Missing a ' " ' from the include statement?

Re: opening a directory

Posted: Tue Mar 01, 2011 11:25 am
by Jonah Bron

Re: opening a directory

Posted: Tue Mar 01, 2011 4:35 pm
by social_experiment
Slightly off topic here but i need to get the latest version of that.

Re: opening a directory

Posted: Wed Mar 02, 2011 1:00 pm
by danwguy
Good find on that missing " now I get this error...
Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in C:\WEB_ROOT\dirview-class.php on line 7
but here is line 7 ...

Code: Select all

	$TrackDir=opendir($name."/");
so not sure what that error means, there is a ; at the end of that line.

Re: opening a directory

Posted: Thu Mar 03, 2011 10:44 am
by social_experiment

Code: Select all

 // you forgot a ';' here 
 global $data // <------- missing ;
 $TrackDir=opendir($name."/");                        
Errors like that often point to the previous lines above line X.

Re: opening a directory

Posted: Fri Mar 04, 2011 1:01 pm
by danwguy
Thank you so much, everything works great now. This class is going to save me so much time. I am building a "blog" style website with photo galleries included, and now I can just call the class with the dir name to open and it does the rest for me. Thank you again.