Clear all

How to extract a zip file with PHP

1 Posts
1 Users
Reputable Member Admin
Joined: 10 years ago
Posts: 307
Topic starter  

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

But after uploading the zip file to 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 with your filename and save this php file in the same directory as the zip file you want to unzip.

$unzip = new ZipArchive;
$out = $unzip->open('');

if ($out === TRUE) {
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 2 times by Tharindu
This topic was modified 1 year ago by Tharindu

Topic Tags
Back to top button