Solved

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

Posted on 2014-09-23
4
509 Views
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">
	<tr>
		<td width="100" height="10">
		JSON.gz file
		</td>
		<td>
		<input name="photo" type="file" size=33">
		</td>
	</tr>
	<tr>
		<td colspan="2" style="text-align:center;"><input type="submit" value="submit"></td>
	 </tr>
	</table></form>

Open in new window


and I know I've got to do this:

<?php
$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?
0
Comment
Question by:brucegust
  • 2
4 Comments
 
LVL 109

Expert Comment

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

Accepted Solution

by:
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
error_reporting(E_ALL); 
//$jss = '{"id":"tag:search.twitter.com,2005:389903668427763712","objectType":"activity","actor":{"objectType":"person","id":"id:twitter.com:91239297","link":"http://www.twitter.com/OGkush103","displayName":"WalkingLick74","postedTime":"2009-11-20T01:21:39.000Z","image":"https://si0.twimg.com/profile_images/378800000593715086/755411d8bdc495472c2d7ed50e319582_normal.jpeg","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":"http://twitter.com/download/iphone"},"provider":{"objectType":"service","displayName":"Twitter","link":"http://www.twitter.com"},"link":"http://twitter.com/OGkush103/statuses/389903668427763712","body":"You a killer you on twitter, You\'n do NO talking","object":{"objectType":"note","id":"object:search.twitter.com,2005:389903668427763712","summary":"You a killer you on twitter, You\'n do NO talking","link":"http://twitter.com/OGkush103/statuses/389903668427763712","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":"https://api.twitter.com/1.1/geo/id/43d2418301bf1a49.json","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);
//gzclose($f);
//echo 'Finished the GZIP !<br />';
//$f = fopen('jsonTest.gz', 'r' );
$f = gzopen('jsonTest.gz', "r");
$gzStr = gzread($f, 10000);
gzclose($f);
echo 'UNCOMPRESS ZGIP is below -<br />',$gzStr;
 ?><hr><?php
$csv = '';
$jsonArray = json_decode($gzStr,true);
if(!$jsonArray)
  $csv = 'ERROR!,ERROR!,ERROR!,ERROR!,ERROR!,ERROR!,ERROR!';
  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>';
?>
 </body></html>

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.
0
 

Author Comment

by:brucegust
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!

Thanks!
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40343907
0

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