php unzip to other dir

i been using the unzip code for about a year and it works great. But now i want to have the code the unzip the file to a dir i want and not in the dir the file is in.

copy('', '../Demo/');

$file = '../Demo/';

function unzip($file){

    if(!$zip) {return("Unable to proccess file '{$file}'");}


    while($zip_entry=zip_read($zip)) {

       if(!zip_entry_open($zip,$zip_entry,"r")) {$e.="Unable to proccess file '{$zname}'";continue;}
       if(!is_dir($zdir)) mkdirr($zdir,0777);

       #print "{$zdir} | {$zname} \n";

       if(empty($zip_fs)) continue;





function mkdirr($pn,$mode=null) {

  if(is_dir($pn)||empty($pn)) return true;
  $pn=str_replace(array('/', ''),DIRECTORY_SEPARATOR,$pn);

  if(is_file($pn)) {trigger_error('mkdirr() File exists', E_USER_WARNING);return false;}

  if(mkdirr($next_pathname,$mode)) {if(!file_exists($pn)) {return mkdir($pn,$mode);} }
  return false;


Open in new window

Who is Participating?
Ray PaseurConnect With a Mentor Commented:
I don't know what you're missing and I don't really have anything other than suggestions (no time to test this process any time soon).  So here is my suggestion.  

1. Unzip the archive wherever it happens to be.  That part already works, so no magic is needed.

2. After Unzip, copy the files to the destination directory.

3. Unlink the files and the ZIP archive.
sivagnanam chandrakanthTechnical LeadCommented:
see this

fopen and fwrite should come after using fopen of the required directory, in that way you can place the files in specified folder
Have you tried zip_extractto( extract directory)
You can have a  look here
for details.
Ray PaseurCommented:
This may be oversimplifying the question, but why not just move the ZIP archive to the destination directory location you want, then extract the files right there?
armasmikeAuthor Commented:

I was wanting to do just that. this is why i have

copy('', '../Demo/');

$file = '../Demo/';

Open in new window



Open in new window

at the bottom. I was thinking it would do just that unzip in the Demo dir. But it doesn't what am i missing.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.