1

コードイグナイターコードのディレクトリにあるすべての画像をブラウザーに表示する関数を試しているので、次のコードを使用しています。

$imgdir = 'upload/'; //Pick your folder
$allowed_types = array('png','jpg','jpeg','gif'); //Allowed types of files
$dimg = opendir($imgdir);//Open directory
while($imgfile = readdir($dimg))
{

if( in_array(strtolower(substr($imgfile,-3)),$allowed_types) OR
in_array(strtolower(substr($imgfile,-4)),$allowed_types) )
/*If the file is an image add it to the array*/
{$a_img[] = $imgfile;}
}
echo "<ul>";

$totimg = count($a_img);  //The total count of all the images
//Echo out the images and their paths incased in an li.
for($x=0; $x < $totimg; $x++){echo "<li><img src='http://localhost/code/'" . $imgdir . $a_img[$x] . "' /></li>"; echo $imgdir . $a_img[$x];} 
echo "<li><img src='http://localhost/code/upload/corrosivo.jpg' /></li>";
echo "</ul>";

私が理解していないのは、ブラウザで壊れた画像ボックスが表示される理由です:

echo "<li><img src='http://localhost/code/'" . $imgdir . $a_img[$x] . "' /></li>"; echo $imgdir . $a_img[$x];}

そして:

echo "<li><img src='http://localhost/code/upload/corrosivo.jpg' /></li>";

画像が正常に表示されました。

私はすでに変数を確認しており、正しい内容を持っています。

4

0 に答える 0