Solved

How do I write a file to a specific directory?

Posted on 2014-09-26
3
63 Views
Last Modified: 2014-09-26
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
Comment
Question by:brucegust
  • 2
3 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40346412
Maybe something like this:
$out_file = fopen('../JSON_parsed' . $out_file_name, 'wb'); 

Open in new window

0
 

Author Comment

by:brucegust
ID: 40346510
That will work!
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40346518
:-)  Hope so!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question