Part of the EllisLab Network
This thread is a discussion for the wiki article: Unzip
   
 
Unzip
Posted: 08 May 2009 07:58 AM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  8
Joined  04-27-2008

Hello,

I try to unzip file in a foreach loop but it failed

May be I have to close file before start another one ?

dUnzip2: Loading list from ‘End of Central Dir’ index list…

dUnzip2: Returning already loaded file list.

You have some ideas ?

My code

$fichiers scandir DIR_DOWN );
        
        
$nbFichiersTraites 0;
        
        foreach ( 
$fichiers as $fichier {
            
if (strtolower substr $fichier, - ) ) == "zip" AND !is_dir(DIR_DOWN.$fichier)) {
                
// On peut ici dézipper tranquilement
                
$config['fileName']  DIR_DOWN.$fichier;
                
$config['targetDir'DIR_DOWN.$path_unzip;
                
$this->unzip->initialize($config);
                
$this->unzip->unzipAll();

                
//display's error messages
                
echo $this->unzip->display_errors(2);
                    
                    
//display's information messages
                    
echo $this->unzip->display_errors(1);
                    
                    
rename(DIR_DOWN.$path_unzip.substr($fichier,0,- 3),DIR_DOWN.$path_traitement.substr($fichier,0,- 3).'xml');
                
                
$nbFichiersTraites ++;
                
sleep(5);
                
}
            }
        } 
Profile
 
 
Posted: 20 May 2009 01:01 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Avatar
Total Posts:  6
Joined  10-12-2008

Hi Vinz, did you find a solution for this? I have the same problem and i stuck. Thanks + Cheerz

 Signature 

Es gibt keine dummen Fragen, nur dumme Leute die sich nicht trauen zu fragen // There are no stupid questions, only stupid people who don’t dare to ask.

Profile
 
 
Posted: 20 May 2009 01:03 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  8
Joined  04-27-2008

Hey but finally I used the zip native library, works very simply !

Sorry

Profile
 
 
Posted: 20 May 2009 01:53 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Avatar
Total Posts:  6
Joined  10-12-2008

Thanks anyway, i’ll also use the native one.

 Signature 

Es gibt keine dummen Fragen, nur dumme Leute die sich nicht trauen zu fragen // There are no stupid questions, only stupid people who don’t dare to ask.

Profile
 
 
Posted: 13 July 2009 10:58 AM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  25
Joined  12-01-2008

I solved in this way:

$this->load->library('unzip'); 

unset(
$this->unzip);

$this->unzip = new Unzip();

... 
Profile
 
 
Posted: 25 November 2009 08:52 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
RankRank
Total Posts:  299
Joined  11-01-2009

It is working like a charm
except I had to figure out that I have to put

$this->unzip->close(); 

if I want to be able to delete the zip file, after decompressing it.

 Signature 

http://flakron.net

Profile
 
 
Posted: 04 December 2009 04:46 AM   [ Ignore ]   [ # 6 ]  
Summer Student
Avatar
Total Posts:  10
Joined  07-22-2009

i already tried to use but not working.

view/upload.php :

[removed]
        
$(document).ready(function(){
                    
$("#upload").uploadify({
                            uploader
'<?php echo base_url();?>assets/uploadify/uploadify.swf',
                            
script'<?php echo base_url();?>assets/uploadify/uploadify.php',
                            
cancelImg'<?php echo base_url();?>assets/uploadify/cancel.png',
                            
folder'../../assets/upload',
                            
scriptAccess'always',
                            
multifalse,
                            
'onError' : function (abcd{
                                 
if (d.status == 404)
                                    
alert('Could not find upload script.');
                                 else if (
d.type === "HTTP")
                                    
alert('error '+d.type+": "+d.status);
                                 else if (
d.type ==="File Size")
                                    
alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');
                                 else
                                    
alert('error '+d.type+": "+d.text);
                            
},
                            
'onComplete' : function (eventqueueIDfileObjresponsedata{
                                
$.post('<?php echo site_url('asset/uploadify');?>'{filearrayresponse}, function(info{
                                    
$("#target").append(info);   
                                
});
                                
//var json_data_object = eval("(" + response + ")");
                                //filename = json_data_object.file_name;
                                
                                //[removed].replace('<?php echo site_url('asset/step3');?>/'+filename);
                            

                    }
);
            
                    
//function onCompletePost(data) {
                            
                            //alert("test");
                            
                            //[removed] = "<?php echo site_url('asset/uploadify'); ?>";
                    //}
        
});
    
[removed]
<div class="content">
    <
h1><?$title?></h1>
    
<?php echo form_open_multipart('asset/uploadify');?>
        
<div class="data">
          <
div class="step1">
            <
span class="head-step1">Step 2 Upload your zip file : </span>
        <
table>
            <
tr>
                <
td>File</td>
                <
td>
             
<?php echo form_upload(array('name' => 'Filedata''id' => 'upload'));?>
                
</td>
            </
tr>
                <
tr>
                <
td>&nbsp;</td>
                <
td>
             <
a href="[removed]$('#upload').uploadifyUpload();">Upload</a>
                </
td>
            </
tr>
        </
table>
            <
div id='target'>            
            </
div>
          </
div>
        </
div>
    
<?php echo form_close(); ?>
    
<br />
    
<?$link_back?>
</div

controller/upload.php

function uploadify() {
                $data[
'response'json_decode($this->input->post('filearray'));

                
//Access data using php json object
                
$data['file_name'$data['response']->file_name;
               
// $data['file_size'] = $data['response']->file_size;
                //$data['file_type'] = $data['response']->file_type;
                //$data['file_ext'] = $data['response']->file_ext;
                
                //print_r($data);
                
$this->load->library('unzip');

                
$config['fileName'base_url().'assets/upload/'.$data['file_name'];
                
$config['targetDir'base_url().'assets/upload/';
                
$this->unzip->initialize($config);
                if(!
$this->unzip->unzipAll()) {                    
                    print_r
($this->unzip->display_errors(1));
                    
$this->unzip->close(); 
                
}
               
// if(!$this->unzip($data['file_name'])) {
                   // print_r('not ok');
               // }
                
else {                
                    
echo $data['file_name'];
                    
$this->unzip->close(); 
                
}
    } 

it come out these error :

//a lot of this
SeverityWarning

Message
fseek() [function.fseek]stream does not support seeking

Filename
libraries/unzip.php

Line Number
459

//and these two : 
dUnzip2Loading list from 'End of Central Dir' index list...

dUnzip2ZIP File is corrupted or empty 


can anybody help me?

Profile
 
 
Posted: 17 March 2010 10:39 AM   [ Ignore ]   [ # 7 ]  
Summer Student
Total Posts:  21
Joined  02-16-2010

Hi,

The unzip class is extremly good.. but can you pls help me the unziping .rar file.
Existing class only support .zip file but it should also unzip the .rar and .tar files.

Thanks

Profile
 
 
Posted: 05 September 2010 11:09 PM   [ Ignore ]   [ # 8 ]  
Lab Assistant
RankRank
Total Posts:  140
Joined  10-19-2009

nice job! thanks im using it right now

$this->unzip->extract('uploads/my_archive.zip''/path/to/directory/); 

should have ’ on the extract path

$this->unzip->extract('uploads/my_archive.zip''/path/to/directory/'); 

hehe

Profile
 
 
Posted: 18 September 2010 07:00 AM   [ Ignore ]   [ # 9 ]  
Summer Student
Total Posts:  2
Joined  09-18-2010

Thanks

Profile
 
 
Posted: 03 November 2010 06:49 PM   [ Ignore ]   [ # 10 ]  
Grad Student
Avatar
Rank
Total Posts:  37
Joined  11-23-2009

this is working for me - but for some reason, i am getting an extra folder.  instead of unzipping the contents directly to the specified path, or to the current folder - the library is creating a new folder inside the destination… named ‘untitled folder’ for me…

seems like i am making a simple mistake?

Profile
 
 
Posted: 03 November 2010 07:07 PM   [ Ignore ]   [ # 11 ]  
Grad Student
Avatar
Rank
Total Posts:  37
Joined  11-23-2009

trigger happy as always. 
set the third parameter to ‘false’ to enable unzipping to the directory you specify.

Profile
 
 
Posted: 10 May 2011 04:18 PM   [ Ignore ]   [ # 12 ]  
Summer Student
Total Posts:  25
Joined  01-07-2009

I got this error

Fatal errorCall to undefined method CI_User_agent::extract() in C:\wamp\www\... 

I had of course loaded the library, and I have just this one line

function test() {$this->unzip->extract('assets/orders/2485697_template.zip');

I have new ci version I think 2.+ I am not sure, ...

edit: I have checked for zlib using phpinfo() I have it, I am WAMP user ...

 Signature 

http://blog.nemanjasreckovic.com

Profile
 
 
Posted: 24 August 2011 01:40 PM   [ Ignore ]   [ # 13 ]  
Grad Student
Rank
Total Posts:  49
Joined  05-10-2009

Hi All,

i have used this library working fine but only one issue is coming. its not giving any rights to extracted files so i am unable to read files after extraction.

please guide me.

Thanks in Advance

Regards
Usman Abdul Razzaq

Profile