Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function export()
- {
- // Get a database object.
- $db = JFactory::getDbo();
- // Create a new query object.
- $query = $db->getQuery(true);
- // Select fields to get.
- $fields = array(
- $db->quoteName('params')
- );
- // Conditions for which records should be get.
- $conditions = array(
- $db->quoteName('element') . ' = ' . $db->quote('plugin_name'),
- $db->quoteName('folder') . ' = ' . $db->quote('system')
- );
- // Set the query and load the result.
- $query->select($fields)->from($db->quoteName('#__extensions'))->where($conditions);
- $db->setQuery($query);
- $results = $db->loadResult();
- // Namming the filename that will be generated.
- $name = 'file_name';
- $date = date("Ymd");
- $json_name = $name."-".$date;
- // Clean the output buffer.
- ob_start();
- echo $results;
- $fileContent = ob_get_contents();
- ob_end_clean();
- header('Content-disposition: attachment; filename='.$json_name.'.json');
- header('Content-type: application/json');
- echo $fileContent;
- exit();
- }
- function import($_FILES)
- {
- if ($_FILES['fileToUpload']['error'] > 0) {
- echo "<p class='alert alert-error'>An error occurred while uploading!</p>";
- } else {
- $file_name = $_FILES['fileToUpload']['name'];
- $file_ext = strtolower(end(explode(".", $file_name)));
- $file_size = $_FILES['fileToUpload']['size'];
- if (($file_ext == "json") && ($file_size < 50000)) {
- $options = file_get_contents($_FILES['fileToUpload']['tmp_name']);
- // Get a database object.
- $db = JFactory::getDbo();
- // Create a new query object.
- $query = $db->getQuery(true);
- // Fields to update.
- $fields = array(
- $db->quoteName('params') . ' = ' . $db->quote($options)
- );
- // Conditions for which records should be updated.
- $conditions = array(
- $db->quoteName('element') . ' = ' . $db->quote('plugin_name'),
- $db->quoteName('folder') . ' = ' . $db->quote('system')
- );
- // Set the query and execute it.
- $query->update($db->quoteName('#__extensions'))->set($fields)->where($conditions);
- $db->setQuery($query);
- $result = $db->execute();
- echo "<p class='alert alert-success'>Backup file successfully restored!</p>";
- } else {
- if ($file_ext != "json") {
- echo "<p class='alert alert-error'>Invalid file type!";
- } elseif ($file_size > 50000) {
- echo "<p class='alert alert-error'>File size error!</p>";
- }
- }
- }
- return;
- }
- $jinput = JFactory::getApplication()->input;
- $files = $input->files->get('jform1');
- function import($files)
- {
- // rest of code here
- }
- Array
- (
- [test] => Array
- (
- [0] => Array
- (
- [name] => file.png
- [type] => image/png
- [tmp_name] => /tmp/phpXoIpSD
- [error] => 0
- [size] => 34409
- )
- [1] => Array
- (
- [name] => file2.jpg
- [type] => image/jpeg
- [tmp_name] => /tmp/phpWDE7ye
- [error] => 0
- [size] => 99529
- )
- )
- )
- strtolower(pathinfo($filename, PATHINFO_EXTENSION))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement