jbwebdesign Posted February 15, 2009 Report Share Posted February 15, 2009 (edited) I need help with a script that I am working on...... I want have it working properly to scan the directory but I want it to only display the .php files inside my directory.... can anyone help me out with this??? thanks here is the script that I am using...... <?php $dir = "../FORMfields/forms/generated/"; //You could add a $_GET to change the directory $files = scandir($dir); foreach($files as $key => $value){ echo ''; echo $value; echo ' '; echo '';//You could add an icon in here maybe, a link to the file/directory, or a link to list files in that directory } ?> Edited February 15, 2009 by jbwebdesign Quote Link to comment Share on other sites More sharing options...
jbwebdesign Posted February 15, 2009 Author Report Share Posted February 15, 2009 (edited) I ALSO DONT WANT THE . AND .. TO SHOW UP WHEN THE SCANDIR INFO IS DISPLAYED Edited February 15, 2009 by jbwebdesign Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted February 15, 2009 Report Share Posted February 15, 2009 (edited) if ($file != ?.? && $file != ?..? ) { ... echo stuffe here } *edit* check out the glob function for selecting by file extension http://ca2.php.net/glob Edited February 15, 2009 by jlhaslip Quote Link to comment Share on other sites More sharing options...
jbwebdesign Posted February 15, 2009 Author Report Share Posted February 15, 2009 i tried that and it didn't work.... the dots still appear Quote Link to comment Share on other sites More sharing options...
jbwebdesign Posted February 15, 2009 Author Report Share Posted February 15, 2009 I GOT THE CODE TO WORK KIND OF...... HERE IS MY CODE BUT NOW ITS SCANNING THE WRONG DIRECTORY..... IT ONLY SCANS THE DIRECTORY THAT THE PHP FILE IS IN AND NOT THE ONE THAT ITS POINTING TO...... CAN SOMEONE PLEASE HELP ME??? THANKS <?php $dir = '../FORMfields/forms/generated/'; //You could add a $_GET to change the directory $files = scandir($dir); foreach(glob("*.php") as $files => $value){ echo ''; echo $value; echo ' '; echo '';//You could add an icon in here maybe, a link to the file/directory, or a link to list files in that directory } ?> Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted February 15, 2009 Report Share Posted February 15, 2009 (edited) $dir = './'; // change to suit your location needs chdir($dir); // Move to the directory named above $filesg = glob('*.php'); // glob (make a list of) all (*) the php files found in the directory if(empty($filesg)){ echo 'no php files found...die '; die(); // die if no php files found } else { foreach ($filesg as $file) { // echo out the list of files with target name and title echo ''; echo $file; echo ' '; } } ?> Works for me. I kept your Target in there, but please re-think using it to open new windows. Also added the tooltip title. Edited February 15, 2009 by jlhaslip Quote Link to comment Share on other sites More sharing options...
jbwebdesign Posted February 15, 2009 Author Report Share Posted February 15, 2009 THANKS VERY MUCH..... IT WORKS FOR ME NOW TOO Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted February 15, 2009 Report Share Posted February 15, 2009 You are welcome. And please do not use all caps. It is like yelling at someone... we understand that you are in need, but we all volunteer to assist here. Shouting is not polite. Quote Link to comment Share on other sites More sharing options...
jbwebdesign Posted February 15, 2009 Author Report Share Posted February 15, 2009 I'm not shouting...... just didn't realize that i had it in all caps Quote Link to comment Share on other sites More sharing options...
jbwebdesign Posted February 15, 2009 Author Report Share Posted February 15, 2009 if i wanted to use it again in the same page for a different directory, would i have to put closedir($dir); ???? Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted February 15, 2009 Report Share Posted February 15, 2009 I don't think so because there was no opendir() used. Try it and see. You will need to change directories, though. chdir() and $dir Quote Link to comment Share on other sites More sharing options...
jbwebdesign Posted February 15, 2009 Author Report Share Posted February 15, 2009 ok i tried it....i don't seem to need it. thanks a lot for your help, i really appreciate it Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted February 16, 2009 Report Share Posted February 16, 2009 i really appreciate it big_smile That's why we do it... You are most welcome. Be sure to learn something from these Forums and eventually you will also be helping others. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.