Notifications
Clear all

How to extract a zip file with PHP

1 Posts
1 Users
0 Reactions
11 Views
Tharindu
(@tharindu)
Reputable Member Admin
Joined: 10 years ago
Posts: 309
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 change 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 years ago 3 times by Tharindu

   
Quote
Topic Tags
Share:
Back to top button