简体   繁体   中英

Showing Images in PHP

I want to show images residing inside a directory in PHP The code which I wrote was

<?php

$dir = opendir("upload");


while (($file = readdir($dir)) !== false)
  {
  echo "filename: " . $file . "<br />";

  echo "<a href='shoe.php?image_name=".$file."'> <img src='upload/".$file[0]."' width='150' height='150' /></a></td>";

  }
closedir($dir);
?> 

Here the images are not displayed. Only a frame comes for that image and the actual image is not displayed inside that. Where I have went wrong? Can any one please help...

PHP Glob makes it much easier to list directories. You can do something like

$image = glob("*.jpg")
foreach ($image as $filename) {
    echo "$filename size " . filesize($filename) . "\n";
}

替换$file[0]$file ,如$file是不是一个数组,只会返回字符串的第一个字符。

why $file[0]??? $file is correct:

<?php

        $dir = opendir("upload");

        while (($file = readdir($dir)) !== false)
          {
          echo "filename: " . $file . "<br />";

          echo "<a href='shoe.php?image_name=".$file."'> <img src='upload/".$file."' width='150' height='150' /></a>";

          }
        closedir($dir);
    ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM