WordPress.org

Ready to get started?Download WordPress

Forums

Images not displaying (3 posts)

  1. fluvius
    Member
    Posted 6 years ago #

    Hi all,

    I've added the following code to my footer.php template file to display a series of logos held in a 'Sponsors' sub-folder contained within the 'Gallery' directory I've created using the NextGEN plugin:

    <?php
        $physicalPath = ABSPATH . "wp-content/gallery/sponsors/"; # Location of Sponsors Logos in Gallery Folder
        $thumbs = "thumbs/"; # Thumbnails Sub-folder within Sponsors Folder (to be ignored)
    
        if ($handle = opendir($physicalPath)) {
            while (false !== ($file = readdir($handle))) {
                if ($file != "." && $file != ".." && $file != rtrim($thumbs,"/")) {
                    $files[] = $file;
                }
            }
            closedir($handle);
        }
    
        foreach($files as $file) {
            $imageInfo = getimagesize($physicalPath.'/'.$file);
            $physHeight = $imageInfo[1];
            $physWidth = $imageInfo[0];
            echo '<img src="' . $physicalPath . $file . '" title="'.substr($file,0,-4).'" alt="'.substr($file,0,-4).'" height="'.$physHeight.'" width="'.$physWidth.'" />';
        }
    ?>

    Here's a link to the development site. Scroll to the bottom of the page and within the Sponsors panel you'll see the problem; the images aren't displaying - it's as if they can't be found, yet I know for certain they are in the relevant folder on the server because I've checked.
    The width and height elements within the <img> tag are being collected correctly for each image, so it follows that the image must exist for that to happen - so why can't it actually show it? It's got me beat!

    Any ideas where I'm going wrong? I've studied and tweaked the code but to no avail. It's probably pretty straightforward - I'm just tired!

    Thanks in advance for any help.
    Tony.

  2. richarduk
    Member
    Posted 6 years ago #

    Your urls look a little strange.

    home/sites/btbsandpit01.co.uk/public_html/wp-content/gallery/sponsors/bbc.gif

    I would have thought it would be more like

    home/sites/public_html/wp-content/gallery/sponsors/bbc.gif

    OR

    btbsandpit01.co.uk/public_html/wp-content/gallery/sponsors/bbc.gif

  3. fluvius
    Member
    Posted 6 years ago #

    Thanks for your reply RichardUK.

    Your urls look a little strange.

    That's as a result of ABSPATH within the PHP code snippet.
    I also have the same site on my local development PC and a typical <img> URL is "C:\Program Files\xampp\htdocs\wordpress/wp-content/gallery/sponsors/amazon.gif"
    In a similar way to the online version it too doesn't display the images, so I am wondering if the ABSPATH function should be replaced with another, but I can't see why it doesn't work with ABSPATH... curious.

    Tony.

Topic Closed

This topic has been closed to new replies.

About this Topic