繁体   English   中英

为什么在网站特定页面上出现错误:浏览到index1.php文件时内部服务器错误?

[英]Why i'm getting error on the web site specific page: Internal Server Error when browsing to index1.php file ?

我在index1.php中有此代码,并且我将ifle上载到了我的网站托管网站ipage.com上,并保存到了filemanager。

我将其上传到根目录的文件,在根目录下有一个目录:files,内部有一个目录:radar-simulation-files

如果我浏览到我的网站主页,那很好,没有服务器错误消息:

主页

但是,当我浏览到index1.php页面时,出现错误:

index1.php

错误消息是:

内部服务器错误

服务器遇到内部错误或配置错误,无法完成您的请求。

请与服务器管理员联系,并告知他们错误发生的时间以及您可能做的任何可能导致错误的事情。

服务器错误日志中可能会提供有关此错误的更多信息。

在此页面上,我确实右键单击了鼠标和Inspect元素,并且ii看到一个红色的错误:无法加载资源:服务器的状态为500(内部服务器错误)

但是没有更多有关该错误以及导致错误的原因的详细信息。 我想index1.php中的代码有问题

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
    xmlns="http://www.w3.org/1999/xhtml"
    lang="en"
    xml:lang="en"
><head>

<meta
    http-equiv="Content-Type"
    content="text/html; charset=utf-8"
/>

<meta
    http-equiv="Content-Language"
    content="en"
/>

<meta
    name="viewport"
    content="width=device-width; height=device-height; initial-scale=1.0"
/>

<link
    type="text/css"
    rel="stylesheet"
    href="screen.css"
    media="screen,projection,tv"
/>

<title>
    change picture
</title>

</head><body>

<div id="slideCounter"></div>
<div id="slideShow">
<?php

$allowed_types = ['png','jpg','jpeg','gif'];
$imageDir = 'files/radar-simulation-files';
/*
    Assumes this .php is being run from the http root on the same
    domain as the desired image files.
*/

$handle = opendir($imageDir);
while (($imgPath = readdir($handle)) !== false) if (
    in_array(
        strtolower(pathinfo($imgPath, PATHINFO_EXTENSION)),
        $allowed_types
    )) echo '
    <img src="', $imageDir, '/', $imagePath, '" alt="slide" />';
closedir($handle);

?>
<!-- #slideShow --></div>

<script type="text/javascript">(function(d) {

    // user defines

    var
        swapHours = 0,
        swapMinutes = 0,
        swapSeconds = 5,
        swapTotal = (swapHours * 60 + swapMinutes) * 60 + swapSeconds,
        loopSlideShow = true;

    // some handy helper functions

    function classExists(e, className) {
        return RegExp('(\\s|^)' + className + '(\\s|$)').test(e.className);
    }

    function classAdd(e, className) {
        if (classExists(e, className))
        e.className += (e.className ? ' ' : '') + className;
        return true;
    }

    function classRemove(e, className) {
        if (!classExists(e, className)) return false;
        e.className = e.className.replace(
            new RegExp('(\\s|^)' + n + '(\\s|$)'), ' '
        ) . replace(/^\s+|\s+$/g,'');
        return true;
    }

    function textReplace(e, newtext) {
        if (d.innerText) e.innerText = newText;
            else e.textContent = newText;
    }

    function nodeFirst(e) {
        e = e.firstChild;
        while (e && e.nodeType != 1) e = e.nextSibling;
        return e;
    }

    function nodeLast(e) {
        e = e.lastChild;
        while (e && e.nodeType != 1) e = e.prevSibling;
        return e;
    }

    function nodeNext(e) {
        while (e) if ((e = e.nextSibling).nodeType == 1) return e;
        return null;
    }

    function nodePrev(e) {
        while (e) if ((e = e.prevSibling).nodeType == 1) return e;
        return null;
    }

    // slideShow setup

    var
        slideShow = d.getElementById('slideShow'),
        slideCounter = d.getElementById('slideCounter'),
        firstSlide = nodeFirst(slideShow),
        lastSlide = nodeLast(slideShow),
        currentSlide = firstSlide,
        swapCounter;

    classAdd(slideShow, 'ss_scripted');
    classAdd(currentSlide, 'ss_show');

    // slideShow functions

    function showCounter() {
        textReplace(slideCounter, 
            Math.floor(swapCounter / 3600) + ':' +
            (Math.floor(swapCounter / 60) % 60) + ':' +
            swapCounter % 60
        );
    }

    function resetCounter() {
        swapCounter = swapTotal;
        showCounter();
    }

    function makeSlide(newSlide) {
        classRemove(currentSlide, 'ss_show');
        currentSlide = newSlide;
        classAdd(currentSlide, 'ss_show');
    }

    function nextSlide() { 
        resetCounter();
        var newSlide = nodeNext(currentSlide);
        if (newSlide) makeSlide(newSlide);
            else if (loopSlideShow) makeSlide(firstSlide);
    }

    function prevSlide() {
        resetCounter();
        var newSlide = nodePrev(currentSlide);
        if (newSlide) makeSlide(newSlide);
            else if (loopSlideShow) makeSlide(lastSlide);
    }

    function slideUpdate() {
        if (swapCounter--) showCounter(); else nextSlide();
    }

    function startSlideShow() {
        resetCounter();
        setInterval(slideUpdate, 1000);
    }

    // wait for onload to actually start the countdown 

    if (window.eventListener) w.addEventListener('load', startSlideShow, false);
        else w.addEventListener('onload', startSlideShow);

})(document);</script>

<style>
    .ss_scripted img { display:none; }
.ss_scripted .ss_show { display:block; }
</style>
</body></html>

我没有使用NetBeans自行编写代码,但仅在将其上传到根目录后浏览到index1.php时才会发生此错误。

您的变量名为$imgPath而不是$imagePath ,因此在此行将其替换:

echo '<img src="', $imageDir, '/', $imagePath, '" alt="slide" />';

您所看到的页面是Apache在执行请求(例如您的脚本)时出错时按defaut显示的页面。 如您所见,它在开发中并不是很有用,因此您应该尝试启用PHP错误报告*。

* 如何显示PHP错误

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM