Unzip a Zip File in PHP

View: 362    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: Php&mySql   Fields: Other

0 point/0 review File has been tested

It is a computer file, which has its contents in compressed form

Introduction

What is Zip files?

It is a computer file, which has its contents in compressed form

It has .zip or zipx extension. It is also called archives

A zip file contains many files and  other compressed files

It helps us to keep several files together in one zipped folder or directory

If we need the files which is inside zip file format, we must extract or unzip these files

Following is PHP code which is used to unzip a zip file

Use this code snippet for unzip a zip file in PHP.

<?php
 
function unzip($location,$newLocation){ //create PHP function unzip which pass 2 parameters($location,$newLocation) first param is the actual zip file, second param is the destination location or destination path
 
if(exec("unzip $location",$arr)){ // condition pass a exec() function which has 2 parameters first specifies the command which will be executed, second is an output array which will be filled line by line from the command
 
mkdir($newLocation); // This function creates a directory for given name or path,pass 1 parameter which is the path or name for directory
 
for($i = 1;$i< count($arr);$i++){
 
$file = trim(preg_replace("~inflating: ~","",$arr[$i])); // Loop through array and get all lines from an array store these in $file variable and also strip whitespace from start and end
 
copy($location.'/'.$file,$newLocation.'/'.$file); // This function copy the actual file from source path to destination path 2 parameters passed first is the source path and second parameter is destination path
 
unlink($location.'/'.$file); // This function permanently delete the file of given path as a parameter 
 
}
 
return TRUE;
 
}else{
 
return FALSE;
 
}
 
}
 
/* Use above function */
 
if(unzip('zipedfiles/test.zip','unziped/myNewZip')) // This line calls the above function and pass 2 arguments to that function, first argument is actual file and second argument is the destination file
 
echo 'Success!';
 
else
 
echo 'Error';
 
?>

 

Unzip a Zip File in PHP

Unzip a Zip File in PHP Posted on 27-08-2016  It is a computer file, which has its contents in compressed form 5/10 362

Comment:

To comment you must be logged in members.

Files with category

  • How to Picking the Brains of Your Customers with Microsoft’s Text Analytics

    View: 4071    Download: 0   Comment: 0   Author: none  

    How to Picking the Brains of Your Customers with Microsoft’s Text Analytics

    Category: Php&mySql
    Fields: Other

    1.6666666666667/3 review
    With the explosion of machine learning services in recent years, it has become easier than ever for developers to create “smart apps”. In this article, I’ll introduce you to Microsoft’s offering for providing machine-learning capabilities to apps.

  • How to MySqli Tutorial PHP MySqli Extension

    View: 395    Download: 0   Comment: 0   Author: none  

    How to MySqli Tutorial PHP MySqli Extension

    Category: Php&mySql
    Fields: Other

    0/0 review
    PHP provides three api to connect mysql Database.

  • Make Laravel Artisan Commands

    View: 377    Download: 0   Comment: 0   Author: none  

    Make Laravel Artisan Commands

    Category: Php&mySql
    Fields: Other

    0/0 review
    Artisan is the command line tool used in Laravel framework. It offers a bunch of useful command that can help you develop application quickly. Apart from Artisan available commands, you can create your own custom commands to improve your workflow.

  • Check if a Number is a Power of 2

    View: 343    Download: 0   Comment: 0   Author: none  

    Check if a Number is a Power of 2

    Category: Php&mySql
    Fields: Other

    1.5/3 review
    How to check if a number is a power of 2. To understand this question, let’s take some example.

  • Concatenate columns in MySql

    View: 403    Download: 0   Comment: 0   Author: none  

    Concatenate columns in MySql

    Category: Php&mySql
    Fields: Other

    0/2 review
    Artisan is the command line tool used in Laravel framework. It offers a bunch of useful command that can help you develop application quickly. Apart from Artisan available commands, you can create your own custom commands to improve your workflow

  • How to Query NULL Value in MySql

    View: 336    Download: 0   Comment: 0   Author: none  

    How to Query NULL Value in MySql

    Category: Php&mySql
    Fields: Other

    5/1 review
    Misunderstanding NULL is common mistake beginners do while writing MySql query. While quering in MySql they compare column name with NULL. In MySql NULL is nothing or in simple word it isUnknown Value so if you use comparison operator for NULL values...

  • How to Abstract Class in PHP

    View: 374    Download: 0   Comment: 0   Author: none  

    How to Abstract Class in PHP

    Category: Php&mySql
    Fields: Other

    0/0 review
    What is an abstract class in PHP and when to use an abstract class in your application. In this tutorial, we’ll learn about abstract class and their implementation.

  • Use Enums in Rails for Mapped Values

    View: 337    Download: 0   Comment: 0   Author: none  

    Use Enums in Rails for Mapped Values

    Category: Php&mySql
    Fields: Other

    2.5/2 review
    When I worked in a call center, we used to mark cases with different statuses. This allowed upper management to get a handle on where cases stood, what the bottlenecks were and flow of calls. Thankfully it has been a long time since I worked in a...

 

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd