www.webdeveloper.com
Results 1 to 5 of 5

Thread: Beginner - How to display a folder content

  1. #1
    Join Date
    Aug 2012
    Posts
    10

    Beginner - How to display a folder content

    hello,

    I have a php script which displays images with a link to a folder on my server.

    How can i display the folder's content on the same page when someone clicks on one of the image.

    PHP Code:
    echo "<a href=?lien=$Dossier><img src=$Image width=\"100\" height=\"100\" alt=\"Logo\" /></a>";

    $lien opendir("".$_GET['lien'].""); 
    then i don't know

    thanks in advance

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    I like to use glob() and then just do a foreach() on the resulting array.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2012
    Location
    Belgium
    Posts
    66
    making an ajax call would be the cleanest solution (for me^^)

    HTML:
    <a href="" id="example"><img src="<?php print($Image); ?></a>
    <div id="foldercontent"></div>

    JS:
    $('#example').click(function(){
    url = "readfolder.php?folder=<?php print($dossier) ?>";
    jQuery.ajax({
    dataType:'json',
    url: url,
    complete: function(jqXHR, responseText){
    x = (jqXHR.responseText);
    evaled = eval('(' + x + ')');
    var htmlstring = "<ul>";
    jQuery.each (evaled, function(i, val){
    htmlstring += "<li>" + val + "</li>";
    }
    htmlstring += "</ul>";
    $('#foldercontent').html(htmlstring);
    });

    PHP (readfolder.php):
    <?php
    $files = glob($_GET['folder'].'/*');
    $json = json_encode($files);
    print($json);
    ?>

    or something like that ;-)

  4. #4
    Join Date
    Aug 2012
    Posts
    10
    After some tries, i decided to make something simplier. My script will display only one image on each page.

    I found a really good script on the web for displaying a folder's content. The file (index.php) has to be placed in the folder.

    Link

    How can i display the following on the same page as the image. On my page image is displayed on the left and i want to include the folder content on the right.

    Thanks for help and sorry for my english

    screenshot

  5. #5
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    Ignore jQuery or any JavaScript solution.
    @NogDog is right.

    simple

    Code:
    if($count = count($files = glob(getcwd('*.jpg')) > 0): 
    
    foreach($files as $file): 
    
    if(file_exists($file)):
    
    // if you want to show a thumb nail, learn the GD lib. 
    
    ?>
    
    
    <img src="<?php echo $file; ?>">
    
    <?php endif;
    
    endforeach; 
    
    endif;
    
    ?>
    Last edited by Sheldon; 08-13-2012 at 06:39 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles