开发者

printing a UL from an array of images

I am tryi开发者_如何学Cng to print a UL list of images ending with _th.jpg returned from a specific folder. All i get back is array()

<?php
require '../../config.php';
$conn = new PDO(DB_DSN, DB_USER, DB_PASS);

$id = (int)$_GET['id'];
$q = $conn->query("SELECT * FROM cms_page WHERE id=$id"); 
$project = $q->fetch(PDO::FETCH_ASSOC);
$q->closeCursor();

$imagesDir = 'public/images/portfolio/'.$project['slug'].'/';
$images = glob($imagesDir . '*_th.{jpg,jpeg,png,gif}', GLOB_BRACE);

echo $imagesDir ;
print_r($images);

?>

<h1><?=htmlspecialchars($project['title'])?></h1>
<?php 
if ($images < 1) { 
    echo '<div id="slider">';
    echo '<ul>';
        foreach($images as $key => $value) { 
            echo '<li><a href="public/images/portfolio/i-vis/1.jpg" rel="shadowbox[iVis]" title="Fully Content Managed Website"><img src="public/images/portfolio/'.$project['title'].'/'.$value.'.jpg" width="160" height="96" /></a></li>';
        }
    echo '</ul>';
    echo '</div>';
} else { 
    echo 'There are currently no images to display for tihis project.';
}
?>

Anyone got any ideas?


First of all : are you sure you are reading from the right directory ?

What I mean, is : does 'public/images/portfolio/'.$project['slug'].'/' really exist, and is accessible from your script, using this relative path, in this PHP script ?

(You can test that with is_dir, for instance)


As a precaution, when working with files and directories, I like using absolute paths, so I always know to which directory exactly I'm accessing.

For instance, something like this :

$imagesDir = '/var/www/public/images/portfolio/'.$project['slug'].'/';

If you do not know the absolute path to your directories, you can use dirname(__FILE__), to get the absolute path to the current PHP file -- and then, starting from that file, use a relative path ; for instance :

$imagesDir = dirname(__FILE__) . '/public/images/portfolio/'.$project['slug'].'/';

This way, you don't have to care about the current working directory : your path will always be the same, as it's not relative.

If that doesn't work, then first of all, make sure you are accessing the right directory.


<h1><?=htmlspecialchars($project['title'])?></h1>

Is <? a valid PHP opening tag?

Since your last block of PHP code isn't apparently executed (since it would either print an empty ul or the text from the else block) I suspect the PHP doesn't get parsed correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜