1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
$ar_files = ftp_nlist($conn_id, $ftp_logs_dir);
// makes sure there are files
if (is_array($ar_files))
{
// for each file
for ($i=0;$i<sizeof($ar_files);$i++)
{
$st_file = basename($ar_files[$i]);
if($st_file == '.' || $st_file == '..') continue;
// check this is NOT a directory
if (ftp_size($conn_id, $ftp_logs_dir.'/'.$st_file) != -1)
{
$fileparts = explode(".", $st_file);
if(count($fileparts)==2&&$fileparts[1]=="log"&&ereg("^PlayerJoin", $fileparts[0])==true)
{
$filePath = $ftp_logs_dir.'/'.$st_file;
if(ftp_get($conn_id, $current_dir.$st_file, $filePath, FTP_BINARY))
{
$filestodelete[] = $st_file;
}
}
}
}
if ($filestodelete && is_array($filestodelete) && count($filestodelete)>0)
{
sleep(30);
for($i=0 ; $i<count($filestodelete) ; $i++)
{
$st_file = $filestodelete[$i];
$filePath = $ftp_logs_dir.'/'.$st_file;
if(ftp_delete($conn_id, $filePath))
{
echo $st_file."<br/>";
flush();
}
else
{
@ftp_close($conn_id);
echo "Error : cannot delete files from FTP server...";
flush();
// remove all files we cannot delete
for($j=$i ; $j<count($filestodelete) ; $j++)
{
$st_file = $filestodelete[$j];
unlink($current_dir.$st_file);
}
exit;
}
}
}
} |
Partager