Jump to content

[SOLVED] DropDown File Directory


monkeytooth

Recommended Posts

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
Share on other sites


$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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.