Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. function export()
  2. {
  3. // Get a database object.
  4. $db = JFactory::getDbo();
  5.  
  6. // Create a new query object.
  7. $query = $db->getQuery(true);
  8.  
  9. // Select fields to get.
  10. $fields = array(
  11. $db->quoteName('params')
  12. );
  13.  
  14. // Conditions for which records should be get.
  15. $conditions = array(
  16. $db->quoteName('element') . ' = ' . $db->quote('plugin_name'),
  17. $db->quoteName('folder') . ' = ' . $db->quote('system')
  18. );
  19.  
  20. // Set the query and load the result.
  21. $query->select($fields)->from($db->quoteName('#__extensions'))->where($conditions);
  22. $db->setQuery($query);
  23. $results = $db->loadResult();
  24.  
  25. // Namming the filename that will be generated.
  26. $name = 'file_name';
  27. $date = date("Ymd");
  28. $json_name = $name."-".$date;
  29.  
  30. // Clean the output buffer.
  31. ob_start();
  32. echo $results;
  33. $fileContent = ob_get_contents();
  34. ob_end_clean();
  35.  
  36. header('Content-disposition: attachment; filename='.$json_name.'.json');
  37. header('Content-type: application/json');
  38.  
  39. echo $fileContent;
  40. exit();
  41. }
  42.  
  43. function import($_FILES)
  44. {
  45. if ($_FILES['fileToUpload']['error'] > 0) {
  46. echo "<p class='alert alert-error'>An error occurred while uploading!</p>";
  47. } else {
  48. $file_name = $_FILES['fileToUpload']['name'];
  49. $file_ext = strtolower(end(explode(".", $file_name)));
  50. $file_size = $_FILES['fileToUpload']['size'];
  51. if (($file_ext == "json") && ($file_size < 50000)) {
  52. $options = file_get_contents($_FILES['fileToUpload']['tmp_name']);
  53.  
  54. // Get a database object.
  55. $db = JFactory::getDbo();
  56.  
  57. // Create a new query object.
  58. $query = $db->getQuery(true);
  59.  
  60. // Fields to update.
  61. $fields = array(
  62. $db->quoteName('params') . ' = ' . $db->quote($options)
  63. );
  64.  
  65. // Conditions for which records should be updated.
  66. $conditions = array(
  67. $db->quoteName('element') . ' = ' . $db->quote('plugin_name'),
  68. $db->quoteName('folder') . ' = ' . $db->quote('system')
  69. );
  70.  
  71. // Set the query and execute it.
  72. $query->update($db->quoteName('#__extensions'))->set($fields)->where($conditions);
  73. $db->setQuery($query);
  74. $result = $db->execute();
  75.  
  76. echo "<p class='alert alert-success'>Backup file successfully restored!</p>";
  77. } else {
  78. if ($file_ext != "json") {
  79. echo "<p class='alert alert-error'>Invalid file type!";
  80. } elseif ($file_size > 50000) {
  81. echo "<p class='alert alert-error'>File size error!</p>";
  82. }
  83. }
  84. }
  85. return;
  86. }
  87.  
  88. $jinput = JFactory::getApplication()->input;
  89. $files = $input->files->get('jform1');
  90.  
  91. function import($files)
  92. {
  93. // rest of code here
  94. }
  95.  
  96. Array
  97. (
  98. [test] => Array
  99. (
  100. [0] => Array
  101. (
  102. [name] => file.png
  103. [type] => image/png
  104. [tmp_name] => /tmp/phpXoIpSD
  105. [error] => 0
  106. [size] => 34409
  107. )
  108.  
  109. [1] => Array
  110. (
  111. [name] => file2.jpg
  112. [type] => image/jpeg
  113. [tmp_name] => /tmp/phpWDE7ye
  114. [error] => 0
  115. [size] => 99529
  116. )
  117.  
  118. )
  119.  
  120. )
  121.  
  122. strtolower(pathinfo($filename, PATHINFO_EXTENSION))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement