Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 75
  • Last Modified:

How do I write a file to a specific directory?

This code works:

 //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);

Open in new window


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?
0
brucegust
Asked:
brucegust
  • 2
1 Solution
 
Ray PaseurCommented:
Maybe something like this:
$out_file = fopen('../JSON_parsed' . $out_file_name, 'wb'); 

Open in new window

0
 
brucegustAuthor Commented:
That will work!
0
 
Ray PaseurCommented:
:-)  Hope so!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now