PageRenderTime 26ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/admin/modules/ajax_fileupload.php

http://pixie-cms.googlecode.com/
PHP | 193 lines | 157 code | 0 blank | 36 comment | 52 complexity | 97af51b5bb6cf139b80d32288af24d4c MD5 | raw file
  1. <?php
  2. header('Content-Type: text/html; charset=utf-8');
  3. /**
  4. * Pixie: The Small, Simple, Site Maker.
  5. *
  6. * Licence: GNU General Public License v3
  7. * Copyright (C) 2010, Scott Evans
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see http://www.gnu.org/licenses/
  21. *
  22. * Title: AJAX File Upload
  23. *
  24. * @package Pixie
  25. * @copyright 2008-2010 Scott Evans
  26. * @author Scott Evans
  27. * @author Sam Collett
  28. * @author Tony White
  29. * @author Isa Worcs
  30. * @link http://www.getpixie.co.uk
  31. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3
  32. * @todo Tag release for Pixie 1.04
  33. *
  34. */
  35. $refering = NULL;
  36. $refering = parse_url(($_SERVER['HTTP_REFERER']));
  37. if (($refering['host'] == $_SERVER['HTTP_HOST'])) {
  38. if (defined('DIRECT_ACCESS')) {
  39. require_once '../../lib/lib_misc.php';
  40. pixieExit();
  41. exit();
  42. }
  43. define('DIRECT_ACCESS', 1);
  44. require_once '../../lib/lib_misc.php';
  45. /* perform basic sanity checks */
  46. bombShelter();
  47. /* check URL size */
  48. error_reporting(0);
  49. require_once '../../config.php';
  50. include_once '../../lib/lib_db.php';
  51. include_once '../../lib/lib_auth.php';
  52. include_once '../../lib/lib_date.php';
  53. include_once '../../lib/lib_validate.php';
  54. include_once '../../lib/lib_upload.php';
  55. include_once '../../lib/lib_rss.php';
  56. include_once '../../lib/lib_tags.php';
  57. include_once '../../lib/lib_logs.php';
  58. if (isset($GLOBALS['pixie_user']) && $GLOBALS['pixie_user_privs'] >= 1) {
  59. globalSec('ajax_fileupload.php', 1);
  60. extract($_REQUEST); // access to form vars if register globals is off // note : NOT setting a prefix yet, not looked at it yet
  61. $prefs = get_prefs();
  62. extract($prefs);
  63. include_once '../../lang/' . $language . '.php';
  64. // rebuild new form field
  65. if ($form) {
  66. if (first_word($form) == 'image') {
  67. db_dropdown('pixie_files', "", $form, "file_type = 'Image' order by file_id desc");
  68. if (!$ie) {
  69. echo "\n\t\t\t\t\t\t\t\t<span class=\"more_upload\">or <a href=\"#\" onclick=\"upswitch('" . $form . "'); return false;\" title=\"" . $lang['upload'] . "\">" . strtolower($lang['upload']) . "...</a></span>\n\t\t\t\t\t\t\t\t</div>\n";
  70. }
  71. } else if (first_word($form) == 'document') {
  72. db_dropdown('pixie_files', "", $form, "file_type = 'Other' order by file_id desc");
  73. if (!$ie) {
  74. echo "\n\t\t\t\t\t\t\t\t<span class=\"more_upload\">or <a href=\"#\" onclick=\"upswitch('" . $form . "'); return false;\" title=\"" . $lang['upload'] . "\">" . strtolower($lang['upload']) . "...</a></span>\n\t\t\t\t\t\t\t\t</div>\n";
  75. }
  76. } else if (first_word($form) == 'video') {
  77. db_dropdown('pixie_files', "", $form, "file_type = 'Video' order by file_id desc");
  78. if (!$ie) {
  79. echo "\n\t\t\t\t\t\t\t\t<span class=\"more_upload\">or <a href=\"#\" onclick=\"upswitch('" . $form . "'); return false;\" title=\"" . $lang['upload'] . "\">" . strtolower($lang['upload']) . "...</a></span>\n\t\t\t\t\t\t\t\t</div>\n";
  80. }
  81. } else if (first_word($form) == 'audio') {
  82. db_dropdown('pixie_files', "", $form, "file_type = 'Audio' order by file_id desc");
  83. if (!$ie) {
  84. echo "\n\t\t\t\t\t\t\t\t<span class=\"more_upload\">or <a href=\"#\" onclick=\"upswitch('" . $form . "'); return false;\" title=\"" . $lang['upload'] . "\">" . strtolower($lang['upload']) . "...</a></span>\n\t\t\t\t\t\t\t\t</div>\n";
  85. }
  86. } else {
  87. db_dropdown('pixie_files', "", $form, "file_id >= '0' order by file_id desc");
  88. if (!$ie) {
  89. echo "\n\t\t\t\t\t\t\t\t<span class=\"more_upload\">or <a href=\"#\" onclick=\"upswitch('" . $form . "'); return false;\" title=\"" . $lang['upload'] . "\">" . strtolower($lang['upload']) . "...</a></span>\n\t\t\t\t\t\t\t\t</div>\n";
  90. }
  91. }
  92. die();
  93. }
  94. $max_size = 1024 * 100;
  95. $multi_upload = new muli_files;
  96. $file_name = $_FILES['upload']['name'][0];
  97. $file_ext = substr(strrchr($file_name, '.'), 1);
  98. $file_ext = strtolower($file_ext);
  99. if (($file_ext == 'jpg') or ($file_ext == 'gif') or ($file_ext == 'png')) {
  100. $dir = '../../../files/images/';
  101. $file_type = 'Image';
  102. } else if (($file_ext == 'mov') or ($file_ext == 'flv') or ($file_ext == 'avi') or ($file_ext == 'm4v') or ($file_ext == 'mp4') or ($file_ext == 'mkv') or ($file_ext == 'ogv')) {
  103. $dir = '../../../files/video/';
  104. $file_type = 'Video';
  105. } else if (($file_ext == 'mp3') or ($file_ext == 'flac') or ($file_ext == 'ogg') or ($file_ext == 'wav') or ($file_ext == 'pls') or ($file_ext == 'm4a') or ($file_ext == 'xspf')) {
  106. $dir = '../../../files/audio/';
  107. $file_type = 'Audio';
  108. } else {
  109. $dir = '../../../files/other/';
  110. $file_type = 'Other';
  111. }
  112. $file_tags = str_replace('_', " ", $field);
  113. $multi_upload->upload_dir = $dir;
  114. $multi_upload->message[] = $multi_upload->extra_text(4);
  115. $multi_upload->do_filename_check = 'y';
  116. $multi_upload->tmp_names_array = $_FILES['upload']['tmp_name'];
  117. $multi_upload->names_array = $_FILES['upload']['name'];
  118. $multi_upload->error_array = $_FILES['upload']['error'];
  119. $multi_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : 'n';
  120. $multi_upload->extensions = array(
  121. '.png',
  122. '.jpg',
  123. '.gif',
  124. '.zip',
  125. '.mp3',
  126. '.pdf',
  127. '.exe',
  128. '.rar',
  129. '.swf',
  130. '.vcf',
  131. '.css',
  132. '.dmg',
  133. '.php',
  134. '.doc',
  135. '.xls',
  136. '.xml',
  137. '.eps',
  138. '.rtf',
  139. '.iso',
  140. '.psd',
  141. '.txt',
  142. '.ppt',
  143. '.mov',
  144. '.flv',
  145. '.avi',
  146. '.m4v',
  147. '.mp4',
  148. '.gz',
  149. '.bz2',
  150. '.tar',
  151. '.7z',
  152. '.svg',
  153. '.svgz',
  154. '.lzma',
  155. '.sig',
  156. '.sign',
  157. '.js',
  158. '.rb',
  159. '.ttf',
  160. '.html',
  161. '.phtml',
  162. '.flac',
  163. '.ogg',
  164. '.wav',
  165. '.mkv',
  166. '.pls',
  167. '.m4a',
  168. '.xspf',
  169. '.ogv'
  170. );
  171. $multi_upload->upload_multi_files();
  172. if (lastword($multi_upload->show_error_string()) == 'uploaded.') {
  173. $sql = "file_name = '$file_name', file_extension = '$file_ext', file_type = '$file_type', tags = '$file_tags'";
  174. $ok = safe_insert('pixie_files', $sql);
  175. if (!$ok) {
  176. $message = $lang['file_upload_error'];
  177. } else {
  178. $messageok = $multi_upload->show_error_string();
  179. logme($messageok, 'no', 'folder');
  180. safe_optimize('pixie_files');
  181. safe_repair('pixie_files');
  182. }
  183. } else {
  184. $message = $multi_upload->show_error_string();
  185. }
  186. print $message;
  187. }
  188. /* This file should be merged as an include or merged directly into another file instead of it being directly accessed like this. */
  189. } else {
  190. header('Location: ../../../');
  191. exit();
  192. }
  193. ?>