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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.