user3732944 user3732944 - 2 months ago 9
HTML Question

php Local host is currently unable to access this request



<?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>





My html and javascript seemed to work just fine previously with hardcoded image names. I am now using php to input images from a text file but now it doesn't seem to work. I get that the local host is currently unable to handle this request error.

I tried to write a simple php program such as this and this seems to work just fine. I'm sure I'm missing something very silly but can't seem to figure it out. Please help



<?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>




Answer

You shouldn't get anything:

if (...) {
    ...
}
fclose($handle);   
else {           // syntax error: "unexpected else (T_ELSE)"

You cannot have any code "between" the } and else. They MUST be next to each other:

 if (...) {
      ...
 } else { 
    ...
 }

Since that's a fatal syntax error, the script dies, and probably causes a 500 error in your server.

Comments