Bruce Gust
asked on
How do I write a file to a specific directory?
This code works:
The only thing I need to improve on is that the uncompressed file is written to the same directory as the compressed file. How do I set things up so it writes to ../JSON_parsed?
//This decompresses the file
$file_name = '00_8ptcd6jgjn201311060000_day.json.gz';
// Raising this value may increase performance
$buffer_size = 4096; // read 4kb at a time
$out_file_name = str_replace('.gz', '', $file_name);
// Open our files (in binary mode)
$file = gzopen($file_name, 'rb');
$out_file = fopen($out_file_name, 'wb');
// Keep repeating until the end of the input file
while(!gzeof($file)) {
// Read buffer-size bytes
// Both fwrite and gzread and binary-safe
fwrite($out_file, gzread($file, $buffer_size));
}
// Files are done, close files
fclose($out_file);
gzclose($file);
The only thing I need to improve on is that the uncompressed file is written to the same directory as the compressed file. How do I set things up so it writes to ../JSON_parsed?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-) Hope so!
ASKER