Jump to content

PHP/jQuery get file as uploaded


hackalive

Recommended Posts

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.

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.