I have a special request for my PHP application.
Basically, an user can request a backup of his data as a TAR
file. This archive contains a JSON
file with the database informations (Profile, Various data, etc.) and a directory with all the files the user has upload since his registration.
So far, I've made the following code:
$phar = new PharData($output_filename);
$table_dump = self::dump_tables($customers);
$manifest = array();
$manifest['generation_time'] = time();
$manifest['manifest_version'] = self::DUMP_VERSION;
$phar->addFromString(self::MANIFEST_FILE, json_encode($manifest) );
$phar->addFromString(self::DATA_FILE, json_encode($table_dump) );
sql::select(file::sql_table, sql::true, file::sql_key);
$files_list = sql::fetch_all();
if ($files_list) foreach($files_list as $file_guid) {
$file_path = file::forge_file_path($file_guid);
if(is_file($file_path))
$phar->addFile($file_path, basename($file_path));
}
return $output_filename;
It successfully returns a valid path with a valid TAR
file that i can download. Today, the download is automatically started through a PHP Header
but it takes ages to pack the TAR
.
What I would like to know is: Is it possible to start downloading the file while it's being created ? (As a TAR
file is made of collapsed files.)
Thanks for your help.