LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-29-2010, 08:43 PM   #1
vijaysince89
LQ Newbie
 
Registered: Oct 2010
Posts: 18

Rep: Reputation: 0
Question How to unzip the *.bz2 file using php coding?


Hello everyone,
Below is my code to create *.bz2 file.

<?php

//Moving file to temporary directory for compression

move_uploaded_file($_FILES["file"]["tmp_name"],"c:/" . $_FILES["file"]["name"]);

$url="c:/".$_FILES["file"]["name"];

//File compression

$file_pointer = fopen($url, "r");

$file_read = fread($file_pointer, filesize($url));

fclose($file_pointer);

$temp= pathinfo($_FILES["file"]["name"]);

$filename = "c:/".$temp['filename'].".bz2";

$bz = bzopen($filename, "w");

bzwrite($bz, $file_read);

bzclose($bz);

unlink($url);

//File decompression

$bz = bzopen($filename,"r");

$str = bzread($bz);

bzclose($bz);

$file_pointer = fopen ($url,"w+");

fwrite($file_pointer,$str);

fclose($file_pointer);


echo "Compression Done";

?>

Anyone know, how to unzip the file ? I've tried the above code to unzip it but it creates only 1kb of file for any files. Any ideas?

Thank you,

Regards,
Vijay......
 
Old 11-29-2010, 11:12 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Read the documentation for bzread (http://www.php.net/manual/en/function.bzread.php):
Code:
length
    If not specified, bzread() will read 1024 (uncompressed) bytes at a time.
Length is limited to 8192 according to a comment on php.net, so you might want to use a loop to extract the file.
 
Old 11-30-2010, 01:16 AM   #3
vijaysince89
LQ Newbie
 
Registered: Oct 2010
Posts: 18

Original Poster
Rep: Reputation: 0
Got it. Thank you.
 
Old 11-30-2010, 07:47 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Moved: This thread is more suitable in Programming.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP coding alaios Programming 4 06-12-2010 08:59 PM
What is the difference between using "jar xvf" and "unzip" to unzip the zip-file? thomas2004ch Linux - Newbie 4 08-27-2009 05:11 AM
How to unzip/uncompress .tar.bz2 rajeshsfo Linux - Software 3 08-20-2006 12:48 AM
how to unzip a ***.tar.bz2 file in Windows RajRed General 17 11-04-2005 09:47 AM
What to use to unzip *.bz2 CodeWarrior Slackware 6 06-03-2003 10:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration