hackalive Posted October 28, 2011 Share Posted October 28, 2011 Hi guys, I need some PHP/jquery code that constantly checks a folder for when files are added to it, then grabs the file/s and processes them through a php function. Any ideas how I can automate this, I am happy for a browser window to have to be open to do it (that would be the only way I think) but now I just need the web based code to go with it. Any help/suggestions are much appreciated. Cheers in advance. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 28, 2011 Share Posted October 28, 2011 I would recommend using a database, but this is a non-database way (NOT TESTED!): function checkFolder(){ $.ajax({ type: "GET", url: "/process/checkfolder.php", success: function(data){ $("#myDiv").append(data); } }); } setInterval("checkFolder()", 10000); // Run checkFolder every 10 seconds session_start(); if(!isset($_SESSION['last_check'])) $_SESSION['last_check'] = 0; $last_check = $_SESSION['last_check']; $_SESSION['last_check'] = time(); $newest_files = array(); foreach(glob("folder/*.*") as $file){ if(filemtime($file) >= $last_check){ $newest_files[] = $file; } } echo "<div>".implode("</div><div>", $newest_files)."</div>"; 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.