fileupload.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /* Copyright (C) 2011-2012 Regis Houssin <regis.houssin@capnetworks.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 <http://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('NOREQUIREUSER')) define('NOREQUIREUSER','1');
  23. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
  24. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  25. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  26. if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
  27. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
  28. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show
  29. if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
  30. //if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  31. //if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
  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. header('Pragma: no-cache');
  42. header('Cache-Control: no-store, no-cache, must-revalidate');
  43. header('Content-Disposition: inline; filename="files.json"');
  44. header('X-Content-Type-Options: nosniff');
  45. header('Access-Control-Allow-Origin: *');
  46. header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE');
  47. header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size');
  48. switch ($_SERVER['REQUEST_METHOD']) {
  49. case 'OPTIONS':
  50. break;
  51. case 'HEAD':
  52. case 'GET':
  53. $upload_handler->get();
  54. break;
  55. case 'POST':
  56. if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
  57. $upload_handler->delete();
  58. } else {
  59. $upload_handler->post();
  60. }
  61. break;
  62. case 'DELETE':
  63. $upload_handler->delete();
  64. break;
  65. default:
  66. header('HTTP/1.0 405 Method Not Allowed');
  67. exit;
  68. }
  69. $db->close();