Forums

[resolved] Exec-PHP issues with readdir() function... (5 posts)

  1. jderosa3
    Member
    Posted 3 years ago #

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

    <?php
    	$handle = opendir ('http://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(http://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?

  2. Otto
    Tech Ninja
    Posted 3 years ago #

    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.

  3. jderosa3
    Member
    Posted 3 years ago #

    I have tried changing

    this:

    <?php
    	$handle = opendir ('http://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...

  4. jderosa3
    Member
    Posted 3 years ago #

    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?

  5. jderosa3
    Member
    Posted 3 years ago #

    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='http://www.mydomain.com{$jpg}' /><br />";
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.