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
https://forums.phpfreaks.com/topic/249996-phpjquery-get-file-as-uploaded/
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>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.