open($zipFilePath); if ($result === TRUE) { $zip->extractTo($extractTo); $zip->close(); return true; } else { // Error handling based on ZipArchive result code $errorMessages = [ ZipArchive::ER_MULTIDISK => 'Multi-disk zip archives not supported', ZipArchive::ER_RENAME => 'Renaming temporary files failed', ZipArchive::ER_CLOSE => 'Closing zip archive failed', ZipArchive::ER_SEEK => 'Seek error', ZipArchive::ER_CRC => 'CRC error', ZipArchive::ER_WRONG_PASSWORD => 'Wrong password', ZipArchive::ER_BADZIPFILE => 'Not a zip archive', ZipArchive::ER_DELETED => 'Entry has been deleted', ZipArchive::ER_EXISTS => 'File already exists', ZipArchive::ER_INCONS => 'Zip archive inconsistent', ZipArchive::ER_MEMORY => 'Memory allocation failure', ZipArchive::ER_CHANGED => 'Entry has been changed', ZipArchive::ER_COMPNOTSUPP => 'Compression method not supported', ZipArchive::ER_EOF => 'Premature EOF', ZipArchive::ER_INVAL => 'Invalid argument', ZipArchive::ER_NOENT => 'No such file', ZipArchive::ER_NOPROG => 'No progress indicator', ZipArchive::ER_INCOM => 'Incomplete zip archive', ]; echo 'Failed to unzip the file. Error: ' . $errorMessages[$result] ?? 'Unknown error'; return false; } } // Function to get the download URL from the response function getDownloadUrl($response) { // Extract URL from response $lines = explode("\n", $response); return trim($lines[0]); // Assuming the URL is the first line } // Function to get the version from the response function getVersionFromResponse($response) { $lines = explode("\n", $response); $versionLine = $lines[1] ?? ''; return trim($versionLine); } // Create unzip directory if it does not exist if (!is_dir($unzipDir)) { mkdir($unzipDir, 0755, true); } // Download the update details $response = file_get_contents($updateUrl); if ($response === false) { die("Failed to get update details."); } // Extract the download URL and version from the response $downloadUrl = getDownloadUrl($response); $version = getVersionFromResponse($response); // Validate the download URL if (filter_var($downloadUrl, FILTER_VALIDATE_URL) === false) { die("Invalid download URL."); } // Download the update package if (downloadFile($downloadUrl, $zipFilePath)) { // Check if the ZIP file was downloaded successfully if (file_exists($zipFilePath) && filesize($zipFilePath) > 0) { // Extract the downloaded file if (unzipFile($zipFilePath, $unzipDir)) { // Remove configuration.php from the extracted files // Move extracted files to the WHMCS directory $files = glob($unzipDir . '*'); // Get all files and directories in unzipDir foreach ($files as $file) { $basename = basename($file); $dest = $whmcsDir . $basename; if (is_dir($file)) { // Move directories rename($file, $dest); } else { // Move files rename($file, $dest); } } // Clean up unlink($zipFilePath); // Delete the ZIP file array_map('unlink', glob("$unzipDir/*.*")); // Delete remaining files in unzipDir rmdir($unzipDir); // Remove the unzip directory // Display success message with version and instructions $updateMessage = "

Congratulations!

WHMCS installation completed successfully.

Go to your /install directory to complete the installation.

After the installtion is completed, please delete the /install directory.

;"; echo $updateMessage; } else { echo "Failed to unzip the update file."; } } else { echo "The ZIP file does not exist or is too small."; } } else { echo "Failed to download the update file."; } ?>
Go Back to LicenseDash WHMCS Manager