Unzip file in server using PHP ZipArchive
Once i wanted to upload WordPress folder which contains 1000's of files, if i choose to upload those files using FTP it will take much time.So i decided to upload it as zip file and extract it using php code. After googling i got a good source, how to extract / unzip file in server.
Is this post useful? Please comment below :-)
Follow the steps to unzip file in server:
- Create a file [root-dir(or)your-preferred-dir]/unzip-file.php in your server.
- Copy/paste below code in unzip-file.php and save it.
$zip = new ZipArchive;
$res = $zip->open('wordpress.zip');//File name in server.
if ($res === TRUE) {
$zip->extractTo('blog/');//Destination directory
$zip->close();
echo 'successfully extracted';
} else {
echo 'failed';
}
- Upload your zip file in the same folder http://www.example.com/file.zip or your prefered folder as mentioned in above code.
Is this post useful? Please comment below :-)
Comments
Post a Comment