On Thursday, October 11, 2012 11:10:46 PM tamouse mailing lists wrote: > On Thu, Oct 11, 2012 at 8:02 PM, David McGlone <da...@dmcentral.net> wrote: > > Dear everybody :-) > > > > I wanted to thank everyone for helping me out on the stuff that I had been > > trying to do in the last couple weeks. I know I was unorganized, confused, > > flustered and burnt out. But after all the feedback, and getting a swift > > kick in the arse from Jim and Govinda telling me not to let anyone > > intimidate me, and quite a few other good points, I went back to my > > original plan and used opendir. After I got this down and understood it, > > It made me realize how glob worked and I wrote the same thing using glob > > as I did with opendir. I feel good about this and what's even better, I > > killed 2 birds with 1 stone.. LOL Anyway, I just wanted to let everyone > > know I appreciated all the feedback. :-) > > > > <!-- using opendir--> > > $page = $_SERVER['PHP_SELF']; > > > > //directories > > $dirBase = "images/property_pics"; > > > > > > //get album > > $get_the_album = $_GET['album']; > > > > if (!$get_the_album){ > > echo "<p />Select an album:<p />"; > > $handle = opendir($dirBase); > > while(($file = readdir($handle)) !==FALSE){ > > if(is_dir($dirBase."/".$file) && $file != "." && $file != ".."){ > > echo "<a href='$page?album=$file'>$file</a><br />"; > > } > > } > > closedir($handle); > > } > > else{ > > > > if(!is_dir($dirBase."/".$get_the_album) || strtr($get_the_album, ".") > > !=NULL> > > || strtr($get_the_album, "\\") !=NULL){ > > > > echo "Album does not exist."; > > } > > > > > > else { > > > > // echo "$get_the_album"; > > $handle = opendir($dirBase. "/" . @$get_the_album); > > while(($file = readdir($handle)) !== FALSE){ > > if ($file != "." && $file != ".."){ > > > > > > echo "<div id='imageStack'><a href='$dirBase/$get_the_album/$file' > > rel='lightbox[image]'><img src=$dirBase/$get_the_album/$file height='150' > > width='150'></a><br /></div>"; > > > > } > > } > > closedir($handle); > > } > > > > } > > > > <!--end of using opendir--> > > > > <!start of using glob--> > > function myglob(){ > > > > $result = mysql_query("SELECT * FROM properties"); > > > > while($row = mysql_fetch_array($result)){ > > > > $MLS_No = $row['MLS_No']; > > > > } > > > > $images = glob('images/property_pics/' .$MLS_No.'/*'); > > foreach ($images as $image){ > > echo "<div id='imageStack'><a href='$image' > > rel='lightbox[MLS_No]'><img > > > > src='$image' width='200' height='200'></a></div>"; > > > > } > > > > } > > <!--end of using glob--> > > -- > > David M. > > Hi, David, glad you're sticking with it. > > I don't understand what you're trying to do here, though: > > if(!is_dir($dirBase."/".$get_the_album) || strtr($get_the_album, ".") > > !=NULL> > > || strtr($get_the_album, "\\") !=NULL){ > > > > echo "Album does not exist."; > > }
It's suposed to be strstr. This was an attempt to make sure that nobody could get into any directories lower than the directory that contained the image folders. Funny thing is it was still working with my typos. There probably is a better way to do it, but by breaking it down is how I was able to understand it. anyway I fixed it and It should look like this: if(!is_dir($dirBase."/".$get_the_album) || strstr($get_the_album, ".") !=NULL || strstr($get_the_album, "/") !=NULL || strstr($get_the_album, "\\") !=NULL){ echo "Album does not exist."; } > > > > echo "Album does not exist."; > > } > > PHP function strtr takes 2 or 3 arguments, but if only supplying a > simple string for argument 2, you *must* supply a string for argument > 3 as well. > > When I try this: > > $ php -r '$s = strtr("a string","."); var_dump($s);' > > This is the result: > > PHP Warning: strtr(): The second argument is not an array in Command > line code on line 1 > PHP Stack trace: > PHP 1. {main}() Command line code:0 > PHP 2. strtr() Command line code:1 > bool(false) > > which indicates the strtr function call failed. > > What is it you want to do there? Are to trying to see if > $get_the_album contains a "." or a backslash? If so, you will want to > use some sort of search or match facility, not the character > substitution function of strtr. If so, something like this will work > instead: > > if ( > ! is_dir($dirBase."/".$get_the_album) // this is not a directory > > || ! strpos($get_the_album, '.') // directory name does > > not contain a period > > || ! strpos($get_the_album, '\') // directory name does > > not contain a backslash > ) > { > echo "Album does not exist."; > } > > > If that isn't what you want to do, could you provide a simple sentence > (not code) of what you want to do there? Later when I get home from work about 1, I am going to run your example so I can see the differences. -- David M.