0

I have googled and read articles but nothing seems to work how I want it to work so I'll try my best to put it into perspective here and hope that someone can help this idea become more than just that.

I am EXTREMELY new to php and I can't seem to wrap my head around all of it just yet, I only have a basic idea of certain usages that I can do with it however with bigger ideas, like this one. I am at a loss. If I need to explain it better, please let me know and I can try my best.

Main page index.php in a list:

Folder name (# of images in directory)
Folder name (# of images in directory)

Or if it has a subfolder it is:

Click main category link and displays these links to sub directory

 - Sub Folder Name (# of images in directory)
 - Sub Folder Name (# of images in directory)

Then when you click on the subfolder or folder link, it takes you to:

index.php?cat=Folder name or index.php?cat=Subfolder name And displays the images (not lists them) in the folder or subfolder.

Any help is appreciated.

I have tried this and it seems to work but only for one level directory and not sub directories, I also cannot seem to get the number of images in the folder to show up either..

index.php

<?php
    $path = 'uploads';
    $folders = glob($path.'/*');
    echo '<ul>';
    foreach ($folders as $folder) {
        echo '<li><a href="images.php?folder='.$folder.'">'.$folder.'</a></li>';
    }
    echo '</ul>';
    ?>

images.php

<?php
if (isset($_GET['folder'])) {
    $folder = $_GET['folder'];
}
$singleImages = array();
foreach (glob($folder . '/*.{jpg,jpeg,png,gif}', GLOB_BRACE) as $image) {
    $imageElements = array();
    $imageElements['source'] = $image;
    $singleImages[$image] = $imageElements;
}
foreach ($singleImages as $image) {
    echo '<a href="'.$image['source'].'"><img src="'.$image['source'].'"></a>';
}
?>

----------AND UPDATE----------
I would ideally love for it to display a certain number per page and have a pagination if it goes over that number? That might be dreaming a little too big with the directories and sub-directory displays.


I hope this makes sense. I've been working on this for over a week now and this is only as far as I have gotten with it. Thank you for any suggestions/tips/help. I really appreciate even the time anyone takes to read this.

CodeChic
  • 13
  • 3
  • You should look into `scandir()` – Derek Pollard Apr 13 '16 at 00:17
  • The answer here explains how to recursively go through a folder and it's subfolders to get their contents. From there you can do what you want with the files found. http://stackoverflow.com/questions/24783862/list-all-the-files-and-folders-in-a-directory-with-php-recursive-function – helllomatt Apr 13 '16 at 00:32
  • The thing about both of these suggestions is that I'm so new to php that I have no idea what exactly to do. But I do appreciate both of these, thank you! Will try to look into it again today since it didn't make sense to me yesterday when I looked through google and the link. – CodeChic Apr 13 '16 at 18:52

0 Answers0