Solved

Extracting Zip File

Posted on 2006-07-10
5
250 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 500 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

717 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