Notifications
Clear all

How to extract a zip file with PHP

1 Posts
1 Users
0 Likes
7 Views
Tharindu
(@tharindu)
Reputable Member Admin
Joined: 8 years ago
Posts: 299
Topic starter  

I was working on a WordPress website migration where customer was moving their WordPress blog to one.com shared hosting. I had a WordPress website in a zip folder.

But after uploading the zip file to one.com hosting account with their file manager. I realized that there's no way to extract the zip file. I didn't want to upload unzipped content over FTP because it would take so much time and I'm on a limited data connection.

So, I used following php snippet to unzip the file I had already uploaded. You need to create a new file and save it with following content. Remember to changed file-name.zip with your filename and save this php file in the same directory as the zip file you want to unzip.

<?php
$unzip = new ZipArchive;
$out = $unzip->open('file-name.zip');

if ($out === TRUE) {
$unzip->extractTo(getcwd());
$unzip->close();
echo 'File unzipped';
} else {
echo 'It did not work';
}
?>

Open file with your browser to unzip the file.

This topic was modified 2 months ago 2 times by Tharindu

   
Quote
Topic Tags
Share:
Back to top button

We use cookies to give you the best online experience. By agreeing you accept the use of cookies in accordance with our cookie policy.