1

I have this code in index1.php and i uploaded the ifle to my site host ipage.com to my filemanager.

The file i uploaded it to the root directory and under the root directory there is a directory: files And inside there is a directory: radar-simulation-files

If i'm browsing to my website main page it's fine no server error message:

Main page

But when i'm browsing to the index1.php page i'm getting the error:

index1.php

The error message is:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

And on this page i did right click on mouse and Inspect element And i i see one error in red: Failed to load resource: the server responded with a status of 500 (Internal Server Error)

But not more details about the error and what make the error. I guess it's something wrong with my code in the 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>

I'm not getting any erorrs on the code it self i'm using netbeans but this error happen only when i'm browsing to index1.php after uploaded it to the root directory.

Haim Shaban
  • 169
  • 1
  • 1
  • 10
  • Look at the server's error log. it'll have details about the 500. Could be somethiung as simple as a php syntax error, or something wrong in the config. no way to tell – Marc B Nov 03 '14 at 21:13
  • Ok i chatted with ipage help operator and he looked at the log error and saw this: 20141103T163925: newsxpressmedia.com/index1.php Shakeel B: PHP Parse error: syntax error, unexpected '[' in /hermes/bosnaweb09a/b379/ipg.newsxpressmediacom/index1.php on line 41 – Haim Shaban Nov 03 '14 at 21:47
  • Line 41 is: $allowed_types = ['png','jpg','jpeg','gif']; how can i fix it ? – Haim Shaban Nov 03 '14 at 21:49
  • Your PHP is too old to support the new `[]` array shortcut notation. – Marc B Nov 03 '14 at 21:57

1 Answers1

0

Your variable is named $imgPath and not $imagePath, so replace it in this line:

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

The page you are seeing is the one Apache shows by defaut when there is some error while executing the request (ie your script). As you see it is not very helpful while in development, so you should try to enable PHP error reporting*.

* How do I get PHP errors to display

Community
  • 1
  • 1
Salem
  • 12,060
  • 3
  • 30
  • 50