Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A PHP script to download Moodle to a shared web space with only FTP access
<?php
$url = "https://download.moodle.org/download.php/direct/stable310/moodle-latest-310.zip";
$zipFile = "moodle-latest-310.zip"; // Local Zip File Path
$extractPath = ".";
$zipResource = fopen($zipFile, "w");
if(!ini_get('allow_url_fopen'))
die("Error: 'allow_url_fopen' is disabled.\n");
// Get The Zip File From Server
$ch = curl_init();
if($ch === false) {
echo "Error :- ".curl_error($ch);
die();
}
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 === false) {
echo "Error :- ".curl_error($ch);
die();
}
curl_close($ch);
/* Open the Zip file */
$zip = new ZipArchive;
if($zip->open($zipFile) != "true"){
echo "Error :- Unable to open the Zip File";
die();
}
echo "Extracting…<br/>\n";
/* Extract Zip File */
$zip->extractTo($extractPath);
$zip->close();
echo "Success.<br/>\n";
echo "Moving contents…<br/>\n";
shell_exec("mv moodle/* moodle/.* .");
shell_exec("rmdir moodle");
echo "Finished.<br/>\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment