Seb Gy Seb Gy - 9 months ago 52
PHP Question

Check hotfolder in php and ajax

Hello I would like to do a track of my files.
I send 2 files by ftp to a hotfolder.

In my page I check the folder "IN" and the folder OUT.
I use ajax with jquery to see on live the evolution every seconds.

So when my 2 files are in the folder "IN", I write on my page "50%".
The files are deleting by the server during the processing and put after in the folder "OUT".
If the files are in folder "OUT", I write "100%".

So, the flow is :

1s = nothing

2s = "50%"

3s = "50%"

4s = nothing

5s = nothing

6s = nothing

7s = nothing

8s = nothing

9s = nothing

10s = "100%"

11s = "100%"

12s = nothing

13s = nothing

14s = nothing


In my php I do this :

$ftp_path_IN = $_GET["path"]."\/IN\/";
$ftp_files_IN = ftp_nlist($ftp_connect, $ftp_path_IN);
$nb = count($ftp_files_IN);
if ($nb==2) {
$p = 50;
$ftp_path_OUT = $_GET["path"]."\/OUT\/";
$ftp_files_OUT = ftp_nlist($ftp_connect, $ftp_path_OUT);
$nb = count($ftp_files_OUT);
if ($nb==2) {
$p = 100;

echo $p.'%';

But It's a problem that my script in execute every second because when the files is changing there folder, I see nothing, so I write nothing.

How can I remember every second that the files passed in my two folders ?

thanks for your help!

OK with
session_start(); $_SESSION['p'] = 50 or $_SESSION['p'] = 100; and echo $_SESSION['p'] = 50; thanks a lot !

Answer Source

since you use php, try working with sessions to store information, also you could just stop running the script every second when the file reached 100%
remove input tag for file not to be submitted again and place a label that fileX was uploaded with success.

hope it helped.