monkeytooth Posted January 13, 2008 Share Posted January 13, 2008 Yea, I'm sure this is listed somewhere on the www and or even here but I am definitely not searching right cause I keep coming up with close but no cigar.. Anyway I'm just trying to make a simple form for myself to help administer one of my sites I'm working on So I can update a little easier, this isn't a boxed site just for reference. But I do have magic quotes enable via my host. Not that that may or may not make a difference but I'm throwing it out there anyway. What I am trying to do is populate a drop down list with a given directory, or if it isn't possible a normal list, though considering the HTML aspect of how to lay both out I would figure its doable either way. The kicker is I just want it to list image files jpg gif bmp png.. alpha-numerically ie: 1.jpg 1.gif a.gif b.jpg I know I gotta use a while loop or a do loop, but this is my first time really playing with directories or contents there of.. so any and all help would be greatly appreciated, thanks in advance. Link to comment https://forums.phpfreaks.com/topic/85794-solved-dropdown-file-directory/ Share on other sites More sharing options...
tinker Posted January 13, 2008 Share Posted January 13, 2008 what code for reading the directories do you already have? Link to comment https://forums.phpfreaks.com/topic/85794-solved-dropdown-file-directory/#findComment-437880 Share on other sites More sharing options...
monkeytooth Posted January 13, 2008 Author Share Posted January 13, 2008 $the_array = Array(); $handle = opendir('/cards'); while (false!== ($file = readdir($handle))) { if ($file!= "." && $file!= ".." &&!is_dir($file)) { $namearr = split('\.',$file); if ($namearr[count($namearr)-1] == 'jpg') $the_array[] = $file; if ($namearr[count($namearr)-1] == 'gif') $the_array[] = $file; } } closedir($handle); is what im working with but I think its probally a crap example to what I want to do overall.. this is the only example I could find out there that was remotely close to what I want to do.. but at the same time not.. Link to comment https://forums.phpfreaks.com/topic/85794-solved-dropdown-file-directory/#findComment-437884 Share on other sites More sharing options...
tinker Posted January 13, 2008 Share Posted January 13, 2008 Here's an amended snippet illustrating how to sort: $d = array(); $dirs=opendir($base); while (($dir=readdir($dirs))!==false) { $d[] = $base.$dir; } sort($d); You might find 'is_file()' and 'is_dir()' useful functions (usually only need one). In the above example you could make two lists, sort each and then merge them so that the dirs are first and all alphabetical. Also when checking the file extension you only need to do files. You might also be interested in mime-content-type, this actually use's the magic number within the header of the file. Link to comment https://forums.phpfreaks.com/topic/85794-solved-dropdown-file-directory/#findComment-437888 Share on other sites More sharing options...
monkeytooth Posted January 13, 2008 Author Share Posted January 13, 2008 WOOT! Ok I think I got it, I found some code I worked up a long time ago that did something similar using tables, after altering it an tinkering with it I think I got what I was looking for.. Thanks anyway Link to comment https://forums.phpfreaks.com/topic/85794-solved-dropdown-file-directory/#findComment-437916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.