Multiple file checking with php and create the file if does not exist -
i have php script checks if of 5 files exist file1, file2, file3, file4, file5 in sequential order
if file1 exist check file2 if file2 exist check file3 if file3 exist check file4 if file4 exist check file5
if of files dont exist create file , if files exist sleep few seconds until 1 of files deleted , create file before executing code
i have logic clear not able put code action
below code
while(file_exists("/var/tmp/test/" . $tempfile) && file_exists("/var/tmp/test/" . $tempfile2) && file_exists("/var/tmp/test/" . $tempfile3) && file_exists("/var/tmp/test/" . $tempfile4) && file_exists("/var/tmp/test/" . $tempfile5)) { sleep (3); } if file 1 exist { if file 2 { if file 3 { if file 4 { create file 5 } else { create file 4 } } else { create file 1 } } else { create file 1 } } else { create file 1 }
is there better way of writing ?
$files = array('f1', 'f2', ...); while (true) { foreach ($files $file) { if (!file_exists($file)) { break 2; } } sleep(3); } touch($file);
Comments
Post a Comment