Solved

Extracting Zip File

Posted on 2006-07-10
5
245 Views
Last Modified: 2010-04-06
Hi there,

   Can you give me a code in PHP to extract the zip files and store that in a prementioned folder?

Thanks.
0
Comment
Question by:gstalin
  • 3
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
BogoJoker earned 500 total points
Comment Utility
Hi gstalin,

I misread the questions and I moved the actual .zip folder.  Here is a nice approach to locate the .zip file though.  Next we just have to find out how to modify .zip files with php and move the inner files.

<?php
// Directory Name
$dirName = 'zips';
// New Directory Name (where to move zip files)
$newDirName = 'zips/zip2';

// Open Directory
$dir = opendir($dirName);

// Read Files
while ($file = readdir($dir))
{
  // Check if file ends in .zip
  if (preg_match('/\.zip$/i', $file))
  {
    // Move the file
    // On Unix you can do this easily by executing a terminal command
    // to move a file: rm oldFileName newLocationAndName

    // General case
    // Get Contents
    $contents = file_get_contents($dirName . '/' . $file);

    // Create a file with the same name
    $newFile = fopen($newDirName . '/' . $file, "x+");
    fwrite($newFile, $contents);
   
    // Close the file handler
    fclose($newFile);
   
    // Echo
    echo "Moved: $dirName/$file to $newDirName/$file";
  }
}

?>

Just set your own $dirName and $newDirName and this should work to move the .zips.  This does not delete the original file!  Just wanted to let you know that.  Therefore it is safe to test with.

Joe P
0
 

Author Comment

by:gstalin
Comment Utility
Hi,

  I have tested your code, but it only moves the .zip extension files. But it not extrcting the Zip files!

Thanks
0
 
LVL 17

Expert Comment

by:BogoJoker
Comment Utility
gstalin, that is what I said it did.  I do not yet know how to extract files from inside a .zip.

Sorry,
Joe P
0
 

Author Comment

by:gstalin
Comment Utility
Ok no problem, Thank you for your all efforts.
0
 

Author Comment

by:gstalin
Comment Utility
thanks Joe,

I got the code for Extracting the Zip.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now