我想知道是否有人能夠幫助我與這個PHP腳本,我正在使用JQuery Nivo幻燈片。該腳本從文本文件中獲取文件名,並根據您通過分頁顯示的頁面顯示它們。PHP如果圖像文件不存在,顯示另一個圖像
如果文件不存在,腳本是否可以顯示另一個圖像?例如,如果image1.jpg不存在於images/work /目錄中,那麼圖像不可用.jpg將會顯示?
腳本:
<?php
echo"
<div class='slider-wrapper theme-custom'>
<div id='slider' class='nivoSlider'>";
$photos=file("photos.txt");
foreach($photos as $image){
$item=explode("|",$image);
if($item[0]==$fields[0]){
$photo=trim($item[1]);
echo"<img src='images/work/$photo' alt='' />\n";
}
}
echo"
</div>
</div>
"?>
打印出來之前用[file_exists()](http://php.net/manual/en/function.file-exists.php)函數檢查圖像文件。 – xeranas