vij Posted August 9, 2009 Share Posted August 9, 2009 I am new to php. I have a small php script that checks for the number of files in a folder and lists them. I am using XAMPP. <?php //full path to your folder from root set_time_limit(0); $path = "c:/vij"; // Open the folder $dir_handle = @opendir($path) or die("Unable to open $path"); // Loop through the files while ($file = readdir($dir_handle)) { if($file == "." || $file == ".." || $file == "index.php" ) continue; echo "<a href=\"$file\">$file</a><br>"; } // Close closedir($dir_handle); ?> Now my question is how do I get the script to run continuosly and list files in the directory whenever some updates(adding or removing files) are done to the directory. Right now I need to keep refreshing the page. Please help! Quote Link to comment Share on other sites More sharing options...
Alex Posted August 9, 2009 Share Posted August 9, 2009 This can't be done with PHP alone. You could make it refresh periodically to update, or you could use AJAX and run something every X seconds/minutes to check if anything has changed, if so update the content. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 9, 2009 Share Posted August 9, 2009 AJAX! function Post(){ var contentType = "application/x-www-form-urlencoded; charset=UTF-8"; var ajaxRequest; try{ ajaxRequest = new XMLHttpRequest(); } catch (e){ try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Your Browser Doesn't support AJAX."); return false; } } } return Array(ajaxRequest,contentType); } setInterval("loadFiles()", 5000); // Run function every 5 seconds... function loadFiles(){ var connect = Post(); connect[0].onreadystatechange = function(){ if(connect[0].readyState == 4){ document.getElementById('files').innerHTML = connect[0].responseText; } } var aboutMe = document.getElementById('aboutMe').value; var va = ''; connect[0].open("POST", '/process/getImages.php', true); // Place your file here.... connect[0].setRequestHeader("Content-Type", connect[1]); connect[0].send(va); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.