So,
I'm applying AJAX to my whole website. All was/is working fine except for 1 piece of code. Every time i try to open this page it'll show me an internal error (500), but the code is fine ( when i try to open it without AJAX it shows completely fine.
This is the code i'm using to call the ajax function:
    function liveaddproduct() {
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    } else {  // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            document.getElementById("content").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","modules/pages/ajax/add-product.php",  true);
    xmlhttp.send();        
}
This is the code what isn't working when using ajax:
//These two lines work fine but as soon as the foreach starts it'll show the internal error
$dir = "media/productfotos/";
                        $folder = glob($dir . '*.{*}', GLOB_ONLYDIR);
                        foreach (new DirectoryIterator($dir) as $img){
                            if ($img->isDir() && !$img->isDot()) {
                                echo "<option value=" . $img . ">" . $img . "</option>";
                            }
                        }
