public function Add() { $this->checkLogin(OpenSms::OPEN_ROLE_ADMIN); if (!isset($_FILES['zip_file'])) { $this->setError('Please select a valid theme file', 'themes_add'); OpenSms::redirectToAction('Index'); } if ($_FILES["zip_file"]["name"]) { $filename = $_FILES["zip_file"]["name"]; $source = $_FILES["zip_file"]["tmp_name"]; $type = $_FILES["zip_file"]["type"]; $name = explode(".", $filename); $accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed'); foreach ($accepted_types as $mime_type) { if ($mime_type == $type) { $okay = true; break; } } $continue = strtolower($name[1]) == 'zip' ? true : false; if (!$continue) { $message = "The file you are trying to upload is not a .zip file. Please try again."; $this->setError($message, 'themes_add'); } $target_path = OpenSms::getDocumentRoot() . $filename; if (move_uploaded_file($source, $target_path)) { $zip = new ZipArchive(); $x = $zip->open($target_path); if ($x === true) { $zip->extractTo(OpenSms::getDocumentRoot() . OpenSms::DESIGN_PATH); $zip->close(); unlink($target_path); $message = "Your themes has been successfully installed"; $this->setNotification($message, 'themes_add'); OpenSms::redirectToAction('Index'); } } else { $message = "There was a problem with the upload. Please try again."; } $this->setError($message, 'themes_add'); OpenSms::redirectToAction('Index'); } $this->setError('Invalid file name', 'themes_add'); OpenSms::redirectToAction('Index'); }