Solved

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

Posted on 2014-09-23
4
526 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 110

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 110

Expert Comment

by:Ray Paseur
ID: 40343907
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 look for a specific file type in a local or remote server directory using PHP.

734 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