Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

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

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
brucegust
Asked:
brucegust
  • 2
1 Solution
 
Ray PaseurCommented:
Just curious - what types of files are you uploading?
0
 
Slick812Commented:
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
 
brucegustPHP DeveloperAuthor Commented:
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
 
Ray PaseurCommented:
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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