• Resolved jderosa3

    (@jderosa3)


    I would like to use a simple PHP script to show all of the images in a directory

    <?php
    	$handle = opendir ('https://www.xxx.com/flash/portfolio/branding/images/');
        while (false !== ($file = readdir($handle))) {
            echo '<img src="'.$file.'"/><br />'.$file.'<br />';
        }
    ?>

    This throws back a couple of errors:

    Warning opendir(https://www.xxx.com/flash/portfolio/branding/images/)
    [function.opendir]: failed to open dir: not implimented in…. “location of exec-php plugin”

    Any ideas how to get a simple script like this to work?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Well, writing it so that it’s not broken code would be a good start.

    The PHP command opendir is trying to open a directory up for reading. However, instead of giving it a directory, you gave it a URL. I wouldn’t expect that to actually work because a URL is not a directory.

    Thread Starter jderosa3

    (@jderosa3)

    I have tried changing

    this:

    <?php
    	$handle = opendir ('https://www.xxx.com/flash/portfolio/branding/images/');
        while (false !== ($file = readdir($handle))) {
            echo '<img src="'.$file.'"/>'.$file.'';
        }
    ?>

    to this:

    <?php
    	$handle = opendir ('../flash/portfolio/branding/images/');
        while (false !== ($file = readdir($handle))) {
            echo '<img src="'.$file.'"/>'.$file.'';
        }
    ?>

    No luck.. is there a javascript snippet that does what I want?

    These above still cause errors with the exec-PHP plugin… not sure what going on…

    Thread Starter jderosa3

    (@jderosa3)

    Ok… I finally have it reading file onto the page, but… they come up with broken icons as if the graphics are not there… here is my new code:

    <?php
    $dir = "./flash/portfolio/branding/images/";
    //open dir
    if ($opendir = opendir($dir))
    {
       //read dir
    while (($file = readdir($opendir)) !== FALSE)
    {
    if ($file!="."&amp;&amp;$file!="..")
    echo $file."<img src='$dir/$file'><br />";
       }
    }
    ?>

    Any ideas?

    Thread Starter jderosa3

    (@jderosa3)

    got it to work! Incase anyone needs to know how to do this:

    <?php
    $dir = "./flash/portfolio/branding/images/";
    $jpgs = glob($dir . "*.jpg");
    
    foreach ($jpgs as $jpg) {
        $jpg = substr($jpg, 1);
        echo "<img src='https://www.mydomain.com{$jpg}' /><br />";
    }
    ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exec-PHP issues with readdir() function…’ is closed to new replies.