I want to upload a json.gz file and uncompress it. How?

Posted on 2014-09-23
Last Modified: 2014-09-25
So I've got this:

<table class="center" border="0"><form enctype="multipart/form-data" action="json_csv_decompress.php" method="Post">
		<td width="100" height="10">
		JSON.gz file
		<input name="photo" type="file" size=33">
		<td colspan="2" style="text-align:center;"><input type="submit" value="submit"></td>

Open in new window

and I know I've got to do this:

$compressed   = gzcompress('Compress me', 9);
$uncompressed = gzuncompress($compressed);
echo $uncompressed;

How can I put those two things together so the user uploads a file and the uploaded file is automatically decompressed?
Question by:brucegust
  • 2
LVL 109

Expert Comment

by:Ray Paseur
ID: 40340433
Just curious - what types of files are you uploading?
LVL 34

Accepted Solution

Slick812 earned 500 total points
ID: 40342782
I really have little IDEA what you mean by this whole question, however from a previous question about JSON and CSV, here is some code to look at -

<html><head><title>GZIP to JSON</title></head><body><h3>GZIP to JSON</h3><?php
//$jss = '{"id":",2005:389903668427763712","objectType":"activity","actor":{"objectType":"person","id":"","link":"","displayName":"WalkingLick74","postedTime":"2009-11-20T01:21:39.000Z","image":"","summary":"Self-Made, Self Paid..... I always had the mind to get it like a man, head first bout my younging Ean! #YOLO","links":[{"href":null,"rel":"me"}],"friendsCount":468,"followersCount":677,"listedCount":0,"statusesCount":25504,"twitterTimeZone":"Alaska","verified":false,"utcOffset":"-28800","preferredUsername":"OGkush103","languages":["en"],"location":{"objectType":"place","displayName":"Boston George Crib"},"favoritesCount":26},"verb":"post","postedTime":"2013-10-15T00:00:53.000Z","generator":{"displayName":"Twitter for iPhone","link":""},"provider":{"objectType":"service","displayName":"Twitter","link":""},"link":"","body":"You a killer you on twitter, You\'n do NO talking","object":{"objectType":"note","id":",2005:389903668427763712","summary":"You a killer you on twitter, You\'n do NO talking","link":"","postedTime":"2013-10-15T00:00:53.000Z"},"favoritesCount":0,"location":{"objectType":"place","displayName":"Mississippi, US","name":"Mississippi","country_code":"United States","twitter_country_code":"US","link":"","geo":{"type":"Polygon","coordinates":[[[-91.65500899999999,30.146096],[-91.65500899999999,34.996099],[-88.097888,34.996099],[-88.097888,30.146096]]]}},"geo":{"type":"Point","coordinates":[31.99686058,-88.72688823]},"twitter_entities":{"hashtags":[],"symbols":[],"urls":[],"user_mentions":[]},"twitter_filter_level":"medium","twitter_lang":"en","retweetCount":0,"gnip":{"matching_rules":[{"tag":null}],"language":{"value":"en"}}}';
//$f = gzopen('jsonTest.gz', 'wb9');
//gzwrite($f, $jss);
//echo 'Finished the GZIP !<br />';
//$f = fopen('jsonTest.gz', 'r' );
$f = gzopen('jsonTest.gz', "r");
$gzStr = gzread($f, 10000);
echo 'UNCOMPRESS ZGIP is below -<br />',$gzStr;
$csv = '';
$jsonArray = json_decode($gzStr,true);
  else {
  if(isset($jsonArray['actor']['id'])) $csv .= $jsonArray['actor']['id'].',';
    else $csv .= 'ERROR!,';
  if(isset($jsonArray['actor']['displayName'])) $csv .= $jsonArray['actor']['displayName'].',';
    else $csv .= 'ERROR!,';
  if(isset($jsonArray['actor']['postedTime'])) $csv .= $jsonArray['actor']['postedTime'].',';
    else $csv .= 'ERROR!,';
  if(isset($jsonArray['generator']['displayName'])) $csv .= $jsonArray['generator']['displayName'].',';
    else $csv .= 'ERROR!,';
  if(isset($jsonArray['geo']['type'])) $csv .= $jsonArray['geo']['type'].',';
    else $csv .= 'ERROR!,';
  if(isset($jsonArray['geo']['coordinates'][0])) $csv .= $jsonArray['geo']['coordinates'][0].',';
    else $csv .= 'ERROR!,';
  if(isset($jsonArray['geo']['coordinates'][1])) $csv .= $jsonArray['geo']['coordinates'][1];
    else $csv .= 'ERROR!';
echo 'The CSV string is - <br />',$csv,'<hr>';

Open in new window

BUT this has nothing to do with Uploading a file, this takes the compressed file, and uncompresses it and then does a json_decode( ) to then get some array parts from it as -
I need actor/id, actor/displayName, actor/postedTime, generator/displayName, geo/type, geo/coordinates/0, geo/coordinates/1

from your other Question

BE WARNED, I do NOT check for any COMMAS in the strings of the JSON, which will really muck it up if it has commas.

Author Comment

ID: 40343902
Thanks, Slick!

Since posting this question, the "uploading" thing isn't going to be an issue simply because the files are over a gig. But your code is helpful, because I will need to convert the uncompressed file into a CSV file, so you were smelling what I had on the stove!

LVL 109

Expert Comment

by:Ray Paseur
ID: 40343907

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

808 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