opening a directory

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

opening a directory

Post 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
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: opening a directory

Post by social_experiment »

Code: Select all

include("dirview-class.php);
Missing a ' " ' from the include statement?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: opening a directory

Post by Jonah Bron »

User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: opening a directory

Post by social_experiment »

Slightly off topic here but i need to get the latest version of that.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: opening a directory

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: opening a directory

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: opening a directory

Post 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.
Post Reply