Use dir and loop through each directory recursively then use file_put_contents To write the index.html file in each subdirectory.