Use fopen to open the file in write / append mode and similar to downloading the data, use fwrite to add the data to the file.