Jump to content

[SOLVED] Unzip file from array in different folder


Hybride

Recommended Posts

Hey everyone,

 

I've been trying to figure out how to unzip a file in a different folder that's stored in an array. I got it to extract properly (get the whole zip name and whatnot), and the system("unzip -qq") works correctly, but only in the same folder.

 

	$arr_theme_data['file_url'] = "/link/to/folder/";
  	$arr_theme_data['file_file'] = "AlgaeWater.zip";
  
     extract($arr_theme_data, EXTR_PREFIX_SAME, "wddx");
    
    echo $arr_theme_data['file_file']; //prints out AlgaeWater.zip, as it should
    
    system("unzip -qq "$arr_theme_data['file_url'].$arr_theme_data['file_file']);//this doesn't

Sorry about the ugliness. Anyone have an idea how to unzip the file?

Ok, figured it out. Found a different script, and messed with it, turns out the extract() was what I needed, and make sure to have absolute paths in your code. (It was a 3D array btw, that's what was giving me the hard time.)

extract($arr_theme_data['file_file'], EXTR_PREFIX_SAME, "wddx");
                      	 
// start up the ZipArchive to extract
               		 	      $zip = new ZipArchive;
                                $res = $zip->open($filePath . $name);
                                if ($res === TRUE) {
                                    // echo  "Zip Success!";
                                    //creates the folder in the demo area and extracts files there.
                                    $zip->extractTo($demoPath);
                                    $zip->close();
                                } else {
                                // http://php.oregonstate.edu/manual/en/function.ziparchive-open.php
                                // to see what kind of error, if any, shows up.
                                    echo 'ZIP FAILED, code:' . $res;
                                }

 

in case someone wants to know what I did.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.