Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need help: directory opens but contents wont display properly

    the code below displays all images located in the current directory.
    my problem is, if i specify a directory name to $filedir, example $filedir = "pictures"; the only thing that would display
    are blank boxes with an X (i think it means unloaded picture).

    anyone had this kind of problem before? need suggestions please. thanks.

    <?php

    // Set $filedir to '.' if in current directory
    $filedir = ".";

    $handle = opendir($filedir);
    echo $filedir;
    while ($filename = readdir($handle)) {

    // One way to get the file extension
    $ext = strtolower(substr(strrchr($filename, '.'),1));

    if ($ext == 'jpeg' || $ext == 'jpg') {
    echo "<img src='$filename'>";
    }
    }
    closedir($handle);

    ?>

    i've tried using $filedir = "./pictures/"; and $filedir = "pictures/"; neither of the two works.

    note: that pictures folder is located in the same directory as the php file.

  • #2
    aku
    aku is offline
    New Coder
    Join Date
    Jan 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php

    $file_dir 
    './' ;
    $handle opendir$file_dir ) ;
    while( 
    false !== ( $file_name readdir$handle ) ) ) {
        
    $file_ext strtolowerpathinfo$file_namePATHINFO_EXTENSION ) ) ;
        if( 
    $file_ext == 'jpeg' || $file_ext == 'jpg' )
            print 
    "<img src=\"$file_name\" />" ;
    }
    closedir$handle ) ;

    ?>


  •  

    Posting Permissions

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