我得到了输出的图像图标

时间:2013-12-27 09:22:42

标签: php html

我知道它正在访问该目录,因为存在正确数量的损坏图标。即使alt='Image not there'不起作用,它也只会扩展其中的元素但不显示任何文本。我尝试了其他脚本显示alt='Image not there',但仍然提供了一个损坏的图像图标。我还尝试简单地回显文件夹中的图像,但仍然有一个破碎的图像图标,所以我做错了什么?它甚至是一个剧本还是正在发生的事情?

 <?php
 $dirname = "C:/uploads/";
 $images = scandir($dirname);
 shuffle($images);
 $ignore = Array(".", "..");
 foreach ($images as $curimg) {
     if (!in_array($curimg, $ignore)) {
         echo "<li><a href='".$dirname.$curimg."'>
         <img src='img.php?src=".$dirname.$curimg."&w=300&zc=1' alt='Image not working' /></a></li>\n ";
      }
 } 
 ?>

2 个答案:

答案 0 :(得分:0)

您应该在此处提供网址而不是本地路径:

   echo "<li><a href='".$dirname.$curimg."'>

   <img src='img.php?src=".$dirname.$curimg."&w=300&zc=1' alt='Image not working' /></a>

$dirname无法访问外部世界,应该是:

www.my.domain.com/uploads /

答案 1 :(得分:0)

您需要在您的(如果您使用的是本地计算机)本地服务器站点文件夹中创建一个文件夹。因为 PHP是服务器端脚本语言。因此只有文件才能正确地移入您的文件夹。然后你可以简单地调用

<?php
$dirname = "uploads/";
    $images = scandir($dirname);
    shuffle($images);
    $ignore = Array(".", "..");
    foreach($images as $curimg){

        if(!in_array($curimg, $ignore)) {
echo "<li><a href='".$dirname.$curimg."'>
<img src='img.php?src=".$dirname.$curimg."&w=300&zc=1' alt='Image not working' /></a></li>\n ";
            }
        } 
?>

如果从本地机器调用图像,则不是逻辑。因为你正在建立网站。本网站不仅显示您的系统。它显示了所有系统。此外,所有系统都不包含uploads文件夹。