<?php
$handle = fopen("pictures_list.txt", "r");
if ($handle) {
$linea = fgets($handle);
$lineb = fgets($handle);
$linec = fgets($handle);
}
fclose($handle);
else {
echo "can't find file";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pictures</title>
<link rel="stylesheet" type="text/css" href="cssstyles.css" />
</head>
<body>
<center>
<h1>Bridge Pictures</h1>
<br />
<p class="ex" align="justify">This site or call.</p>
<br/>
<h3> Click on image to zoom in. Place mouse on image for Time Stamp</h3>
<div id="container">
<ul>
<li>
<a href="<?php echo $linea; ?>">
<figure>
<img src="<?php echo $linea; ?>" width="400"/>
<figcaption> <?php echo $linea; ?> </figcaption>
</figure>
</a>
</li>
<li>
<a href="<?php echo $lineb; ?>">
<figure>
<img src="<?php echo $lineb; ?>" width="400"/>
<figcaption><?php echo $lineb; ?></figcaption>
</figure>
</a>
</li>
<li>
<a href="<?php echo $linec; ?>">
<figure>
<img src="<?php echo $linec; ?>" width="400"/>
<figcaption> <?php echo $linec; ?> </figcaption>
</figure>
</a>
</li>
</ul>
<span class="button prevButton"></span>
<span class="button nextButton"></span>
<br />
<h2><a href=" http://www.xyz/"> Click here for a list of all images </a></h2>
</ul>
</center>
</div>
<script src="jquery-1.4.2.min.js"></script>
<script>
$(window).load(function(){
var pages = $('#container li'), current=0;
var currentPage,nextPage;
var timeoutID;
var buttonClicked=0;
var handler1=function(){
buttonClicked=1;
$('#container .button').unbind('click');
currentPage= pages.eq(current);
if($(this).hasClass('prevButton'))
{
if (current <= 0)
current=pages.length-1;
else
current=current-1;
nextPage = pages.eq(current);
nextPage.css("marginLeft",-604);
nextPage.show();
nextPage.animate({ marginLeft: 0 }, 800,function(){
currentPage.hide();
});
currentPage.animate({ marginLeft: 604 }, 800,function(){
$('#container .button').bind('click',handler1);
});
}
else
{
if (current >= pages.length-1)
current=0;
else
current=current+1;
nextPage = pages.eq(current);
nextPage.css("marginLeft",604);
nextPage.show();
nextPage.animate({ marginLeft: 0 }, 800,function(){
});
currentPage.animate({ marginLeft: -604 }, 800,function(){
currentPage.hide();
$('#container .button').bind('click',handler1);
});
}
}
var handler2=function(){
if (buttonClicked==0)
{
$('#container .button').unbind('click');
currentPage= pages.eq(current);
if (current >= pages.length-1)
current=0;
else
current=current+1;
nextPage = pages.eq(current);
nextPage.css("marginLeft",604);
nextPage.show();
nextPage.animate({ marginLeft: 0 }, 800,function(){
});
currentPage.animate({ marginLeft: -604 }, 800,function(){
currentPage.hide();
$('#container .button').bind('click',handler1);
});
timeoutID=setTimeout(function(){
handler2();
}, 4000);
}
}
$('#container .button').click(function(){
clearTimeout(timeoutID);
handler1();
});
timeoutID=setTimeout(function(){
handler2();
}, 4000);
});
</script>
</body>
</html>
我的html和javascript以前在使用硬编码图像名称时似乎工作得很好。我现在使用php从文本文件中输入图像,但现在它似乎不起作用。我发现本地主机当前无法处理此请求错误。
我试着写一个像这样的简单php程序,这似乎很好用。我确信我错过了一些非常愚蠢的事情,但似乎想不出来。请帮助
<?php
$handle = fopen("pictures_list.txt", "r");
if ($handle) {
$linea = fgets($handle);
$lineb = fgets($handle);
$linec = fgets($handle);
fclose($handle);
}
else {
echo "can't find file";
}
?>
<html>
<head>
</head>
<body>
<ul>
<li>
<a href="<?php echo $linea; ?>">
<figure>
<img src="<?php echo $linea; ?>" width="400"/>
<figcaption> <?php echo $linea; ?> </figcaption>
</figure>
</a>
</li>
<li>
<a href="<?php echo $lineb; ?>">
<figure>
<img src="<?php echo $lineb; ?>" width="400"/>
<figcaption><?php echo $lineb; ?></figcaption>
</figure>
</a>
</li>
</ul>
</body>
</html>
你不应该得到任何东西:
if (...) {
...
}
fclose($handle);
else { // syntax error: "unexpected else (T_ELSE)"
}
和else
之间不能有任何代码。它们必须挨着:
if (...) {
...
} else {
...
}
由于这是一个致命的语法错误,因此脚本将失效,并可能在服务器中导致500错误。