2016-09-22 57 views
0

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

+0

您是否嘗試過嘗試調試?死亡($ LINEA);確保圖像名稱仍然正確? –

+0

當您遇到500錯誤時,您應該檢查服務器上的錯誤日誌,理由如下。 – Barmar

回答

0

你不應該得到任何東西:

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

你不能有}else 「之間」 的任何代碼。他們必須是彼此相鄰:

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

由於這是一個致命的語法錯誤,腳本死亡,並可能導致500錯誤在你的服務器。

+0

哦,我的上帝,我覺得很傻。它現在可以工作,謝謝@Marc B – user3732944

+0

如果你沒有得到那個致命的解析錯誤信息,你可能正在運行error_reporting和display_errors關閉。他們不應該在開發/調試系統上關閉。 –