fileupload.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /* Copyright (C) 2011-2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/core/ajax/fileupload.php
  20. * \brief File to return Ajax response on file upload
  21. */
  22. if (!defined('NOTOKENRENEWAL')) {
  23. define('NOTOKENRENEWAL', '1');
  24. }
  25. if (!defined('NOREQUIREMENU')) {
  26. define('NOREQUIREMENU', '1'); // If there is no menu to show
  27. }
  28. if (!defined('NOREQUIREHTML')) {
  29. define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
  30. }
  31. // Load Dolibarr environment
  32. require '../../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/fileupload.class.php';
  34. error_reporting(E_ALL | E_STRICT);
  35. //print_r($_POST);
  36. //print_r($_GET);
  37. //print 'upload_dir='.GETPOST('upload_dir');
  38. $fk_element = GETPOST('fk_element', 'int');
  39. $element = GETPOST('element', 'alpha');
  40. $upload_handler = new FileUpload(null, $fk_element, $element);
  41. // Feature not enabled. Warning feature not used and not secured so disabled.
  42. if (!getDolGlobalInt('MAIN_USE_JQUERY_FILEUPLOAD')) {
  43. return;
  44. }
  45. /*
  46. * View
  47. */
  48. top_httphead();
  49. header('Pragma: no-cache');
  50. header('Cache-Control: no-store, no-cache, must-revalidate');
  51. header('Content-Disposition: inline; filename="files.json"');
  52. header('X-Content-Type-Options: nosniff');
  53. header('Access-Control-Allow-Origin: *');
  54. header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE');
  55. header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size');
  56. switch ($_SERVER['REQUEST_METHOD']) {
  57. case 'OPTIONS':
  58. break;
  59. case 'HEAD':
  60. case 'GET':
  61. $upload_handler->get();
  62. break;
  63. case 'POST':
  64. if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
  65. $upload_handler->delete();
  66. } else {
  67. $upload_handler->post();
  68. }
  69. break;
  70. case 'DELETE':
  71. $upload_handler->delete();
  72. break;
  73. default:
  74. header('HTTP/1.0 405 Method Not Allowed');
  75. exit;
  76. }
  77. $db->close();