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条)

报告相同问题?

悬赏问题

  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?