?
Solved

Extracting Zip File

Posted on 2006-07-10
5
Medium Priority
?
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
BogoJoker earned 1000 total points
ID: 17075981
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
ID: 17078802
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
ID: 17078837
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
ID: 17079005
Ok no problem, Thank you for your all efforts.
0
 

Author Comment

by:gstalin
ID: 17087744
thanks Joe,

I got the code for Extracting the Zip.
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

764 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