For practice, I am trying to download a zip file, extract it to a directory and then copy its contents to another directory. I have it almost working but I am stuck on the copying part and I am not sure that the whole thing is coded as it should be. I would really appreciate any comments and help so I can learn. The code I have so far is below. Thank you in advance.
<!DOCTYPE html>
<html>
<br><br>
<div align="center">
<head>
<title>
Create directory and extract Wordpress
</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<?php
if (!isset($_POST['submit'])) {
?>
<form action = "" method = "post">
<table>
<tr>
<td style = " border-style: none;"></td>
<td> <h4>
Enter new directory name
</h4>
</td>
<td> </td>
<td>
<input type = "text" style = "width: 220px;"
class = "form-control" name = "add" id = "add" />
</td>
<td> </td>
<td colspan = "2">
<input type = "submit" name = "submit" class = "btn btn-success"
value = "Create & Extract" />
</td>
</tr>
</table>
</form>
<?php
}
else {
createDirectory();
}
?>
</body>
</div>
</html>
<?php
$url = "https://en-ca.wordpress.org/latest-en_CA.zip";
$zipFile = "latest/wp.zip"; // Local Zip File Path
$zipResource = fopen($zipFile, "w");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FILE, $zipResource);
$page = curl_exec($ch);
if(!$page) {
echo "Error :- ".curl_error($ch);
}
curl_close($ch);
$zip = new ZipArchive;
$extractPath = "latest";
if($zip->open($zipFile) != "true"){
echo "Error :- Unable to open the Zip File";
}
$zip->extractTo($extractPath);
$zip->close();
function createDirectory() {
$newDir = $_POST["add"];
mkdir("".$newDir);
}
function mycopy($wpSrc,$newDir) {
$wpSrc = "latest/wordpress/";
$path = pathinfo($newDir);
copy($wpSrc,$newDir);
}
?>