Jump to content

directorie help


EKsparky

Recommended Posts

Ive search and read for hours but no luck

All i want to be able to do is list the directories (folders) within a certain dir(folder)

Ive tried lots of differnt code but nothing works

I found lots of code that will display both files and folders but i want just the folders. 

 

Example of code that work but displays both

 

<?php
if ($handle = opendir('galleries/')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>
<?php

Thanks for any help

Link to comment
Share on other sites

lol You replyed at same time as me  ;D

Anyways i would not have thought id need the complete full path

ie my script is in  var/www/html/tkd4kids/public_html/photos

so if i run it from there i assumed my path would just be just galleries/

I tried it with full path of var/www/html/tkd4kids/public_html/photos/galleries/ but no luck this result was empty not even . ..

Link to comment
Share on other sites

here is my complete working script, maybe this will help...

 

 

<?php
if ($handle = opendir('galleries/')) {
    while (false !== ($file = readdir($handle))) {
        if (is_dir('/home/xxxxx/public_html/_tests/galleries/'.$file) && $file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>

 

where does the script exist?

Link to comment
Share on other sites

or the following works also... try giving an absolute or root path to the opendir...

 

<?php
if ($handle = opendir('galleries/')) {
    while (false !== ($file = readdir($handle))) {
        if (filetype('/home/xxxxx/public_html/_tests/galleries/'.$file) == 'dir' && $file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>

Link to comment
Share on other sites

Thanks for your help fooDigi

That works  ;D

I still can t see how the full path makes so much differnts when my origianl code did work but showed files as well

Any ways its done

Got up this morning with the intention of doing admin area for my gallery

my php is not great so i started with the easiest tast and a that has taken all day lol

Link to comment
Share on other sites

the functions require that you have the complete path or correct relative path, from their perspective, they need to know where you are in the file system. you were just parsing the filename i believe.

 

good luck with your admin area :)

 

*edit - sorry i said they need to be complete paths, which is not true. you can use relative paths. sorry dude. i guess im on some kinda high horse

Link to comment
Share on other sites

I had to have a play as like i said it work b4 without full path

and i managed to edit your script just a bit to get it work with out full path

 

Assuming that the script is in /photos    (full path  var/www/html/tkd4kids/public_html/photos/galleries/)

 

$dirname = "galleries/";
if ($handle = opendir($dirname)) {
    while (false !== ($file = readdir($handle))) {
        if (is_dir($dirname.$file) && $file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>

 

But again thanks for all your help

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.