dopr25398 2009-11-27 11:42
浏览 10
已采纳

从一系列图像中打印UL

I am trying 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?

  • 写回答

2条回答 默认 最新

  • dpgbh20688 2009-11-27 11:47
    关注

    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 absolue 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.


    Hope this helps...

    If it doesn't : first of all, make sure you are accessing the right directory...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ADS生成的微带线为什么是蓝色空心的
  • ¥15 求一下解题思路,完全不懂
  • ¥15 tensorflow
  • ¥15 densenet网络结构中,特征以cat方式复用后是怎么进行误差回传的
  • ¥15 STM32G471芯片spi设置了8位,总是发送16位
  • ¥15 R语言并行计算beta-NTI中tree文件的类型
  • ¥15 如何解读marsbar导出的ROI数据?
  • ¥20 求友友协助弄一下基于STC89C52单片机的声光控制灯原理图
  • ¥15 arduino双向交通灯设计
  • ¥15 有没有会粒子群算法的大能(○゜ε^○)求带不会出收敛图😭