Upload a .zip file to FTP and unzip it using PHP
Solution 1
First you should upload the zip archive to the server. Here is an example of how to do basic FTP things in PHP.
http://www.php.net/manual/en/ftp.examples-basic.php
After that you should be able to unzip the file on the server using the method you described in the question.
Solution 2
You either need access to execute commands or programs on the machine you are uploading to, or the ability to also upload a script that you can execute via a URL. If you are uploading via FTP to a web server directory that can run PHP, then upload your zip archive and the unzip.php file there and load the unzip.php page in your browser.
Solution 3
This is the code for Extract folder in your FTP, create a new Php file copy below code and run it:
$path = getcwd();
$zip = new ZipArchive;
$res = $zip->open('yourZippedFolder.zip');
if ($res === TRUE) {
$zip->extractTo($path.'/maunil/');
$zip->close();
echo 'Successfully Extracted';
}
else
{
echo 'failed to Extract';
}
Beater
Updated on June 08, 2022Comments
-
Beater almost 2 years
I'm trying to make a script that would upload a certain zip file , currently "test.zip", and then unzip it. I found some answers in this website about how to unzip but got no idea how to do it on an FTP server. All using PHP Please.
Current code:
$zip = new ZipArchive; $zip->open('test.zip'); $zip->extractTo('./'); $zip->close();
Thanks again :)