Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A PHP script to download Moodle to a shared web space with only FTP access
$url = "";
$zipFile = ""; // Local Zip File Path
$extractPath = ".";
$zipResource = fopen($zipFile, "w");
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);
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);
/* Open the Zip file */
$zip = new ZipArchive;
if($zip->open($zipFile) != "true"){
echo "Error :- Unable to open the Zip File";
echo "Extracting…<br/>\n";
/* Extract Zip File */
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