jsims281forum Posted September 2, 2008 Share Posted September 2, 2008 Hi I'm currently building a basic CMS which should be able to drop into any basic flat file site and give my users a WYSIWYG interface to edit their pages. I'm using FCKED for the editing functions, and I've got it running nicely, but only if you can hard code the file names into the system, using a simple if statement e.g. if ($_GET["pageid"] == "1" ) { $content = file_get_contents("../index.htm"); //set this to point to the page you want to edit } I'm wondering if anyone can tell me where to start if I want to have the system work out all the file names on the server, i.e. to incorporate a (customisable) file browser that will work on the server. I want the user to log into the system and get a list of all files in their public html directory, so they can click one and load it up in fckedior. I'm currently looking into modifying webfilebrowser, available at http://sourceforge.net/projects/webfilebrowser/. If anyone has any suggestions on how I could achieve this, or even just link to a good basic open source file browser I would be really appreciative. Thanks, James Link to comment https://forums.phpfreaks.com/topic/122368-solved-the-best-way-to-dynamically-know-what-files-are-located-on-a-server/ Share on other sites More sharing options...
zq29 Posted September 3, 2008 Share Posted September 3, 2008 Maybe it's worth looking at the problem from a different angle? Wouldn't it be better if the pages were stored in a database? If you want to fetch the contents of all your html files, you could use a foreach loop and the glob() function. Link to comment https://forums.phpfreaks.com/topic/122368-solved-the-best-way-to-dynamically-know-what-files-are-located-on-a-server/#findComment-632606 Share on other sites More sharing options...
jsims281forum Posted September 3, 2008 Author Share Posted September 3, 2008 Yeah using a database would make my life a lot easier, however this is something that should be able to be retro-fitted to an existing website with the minimum of fuss. I could make a script to automatically load all the files into a database but that would lead to the same issue I think - how to get the system aware of what files are on the server. What I'm really after is a folder that can be uploaded e.g. /cms, and works straight "out of the box" without having to convert the users' site. I've found this bit of code which I think could help, I'll post back if I can get it working. <?php // initialize counter $count = 0; // set directory name $dir = "/bin"; // open directory and parse file list if (is_dir($dir)) { if ($dh = opendir($dir)) { // iterate over file list // print filenames while (($filename = readdir($dh)) !== false) { if (($filename != ".") && ($filename != "..")) { $count ++; echo $dir . "/" . $filename . "\n"; } } // close directory closedir($dh); } } echo "-- $count FILES FOUND --"; ?> I think I might be able to work with this so it populates an array with each file name, then pulls those array values out again to work on? Link to comment https://forums.phpfreaks.com/topic/122368-solved-the-best-way-to-dynamically-know-what-files-are-located-on-a-server/#findComment-632633 Share on other sites More sharing options...
jsims281forum Posted September 3, 2008 Author Share Posted September 3, 2008 P.S. Yeah it looks like glob() function will be the easiest way forward with this. Thanks for pointing me in the right direction. Link to comment https://forums.phpfreaks.com/topic/122368-solved-the-best-way-to-dynamically-know-what-files-are-located-on-a-server/#findComment-632650 Share on other sites More sharing options...
jsims281forum Posted September 3, 2008 Author Share Posted September 3, 2008 Ok, just so anyone else is trying to do the same, the code I've come up with for managing file names is this: $pages = array(); foreach (glob("*.html") as $filename) { //echo "$filename size " . filesize($filename) . "\n<br>"; array_push ($pages,$filename); } foreach ($pages as &$value) { echo "<a href=",$value,">",$value,"</a><br/>"; } Link to comment https://forums.phpfreaks.com/topic/122368-solved-the-best-way-to-dynamically-know-what-files-are-located-on-a-server/#findComment-632791 Share on other sites More sharing options...
Fadion Posted September 3, 2008 Share Posted September 3, 2008 Why use an array and iterate one other time when you can print the value directly: <?php foreach(glob('*.html') as $file){ $filename = basename($file); echo '<a href="' . $file . '">' . $filename . '</a>; } ?> Link to comment https://forums.phpfreaks.com/topic/122368-solved-the-best-way-to-dynamically-know-what-files-are-located-on-a-server/#findComment-632795 Share on other sites More sharing options...
jsims281forum Posted September 3, 2008 Author Share Posted September 3, 2008 Good point, that also works. I like having an array there so I can just call $pages every time I want a file name. Also it wil let me sort the names before they get echo'd, and other funky stuff. I also want to be able to call the list of filenames in various places and ways the system. However I'm no guru, so I might be missing the point. Is using an array pointless even when I want to do things like this? Link to comment https://forums.phpfreaks.com/topic/122368-solved-the-best-way-to-dynamically-know-what-files-are-located-on-a-server/#findComment-632812 Share on other sites More sharing options...
Fadion Posted September 3, 2008 Share Posted September 3, 2008 It makes sense having an array if you're printing the files in more then one place. For the sorting thing, glob() should automatically sort the files if the GLOB_NOSORT parameter isn't set. Each way is mostly the same, so don't bother too much. Link to comment https://forums.phpfreaks.com/topic/122368-solved-the-best-way-to-dynamically-know-what-files-are-located-on-a-server/#findComment-633003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.