Solved

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

Posted on 2014-09-23
4
480 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 33

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hosting images 4 28
Be edit-table when I click the edit button (turn into inputs boxes) 7 28
hasing a url 16 25
website maintenance mode 1 17
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 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