dolibarr  17.0.4
fileupload.php
Go to the documentation of this file.
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 
24 if (!defined('NOTOKENRENEWAL')) {
25  define('NOTOKENRENEWAL', '1');
26 }
27 if (!defined('NOREQUIREMENU')) {
28  define('NOREQUIREMENU', '1'); // If there is no menu to show
29 }
30 if (!defined('NOREQUIREHTML')) {
31  define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
32 }
33 
34 
35 // Load Dolibarr environment
36 require '../../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/fileupload.class.php';
38 
39 error_reporting(E_ALL | E_STRICT);
40 
41 //print_r($_POST);
42 //print_r($_GET);
43 //print 'upload_dir='.GETPOST('upload_dir');
44 
45 $fk_element = GETPOST('fk_element', 'int');
46 $element = GETPOST('element', 'alpha');
47 
48 $upload_handler = new FileUpload(null, $fk_element, $element);
49 
50 // Feature not enabled. Warning feature not used and not secured so disabled.
51 if (!getDolGlobalInt('MAIN_USE_JQUERY_FILEUPLOAD')) {
52  return;
53 }
54 
55 
56 /*
57  * View
58  */
59 
60 top_httphead();
61 
62 header('Pragma: no-cache');
63 header('Cache-Control: no-store, no-cache, must-revalidate');
64 header('Content-Disposition: inline; filename="files.json"');
65 header('X-Content-Type-Options: nosniff');
66 header('Access-Control-Allow-Origin: *');
67 header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE');
68 header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size');
69 
70 switch ($_SERVER['REQUEST_METHOD']) {
71  case 'OPTIONS':
72  break;
73  case 'HEAD':
74  case 'GET':
75  $upload_handler->get();
76  break;
77  case 'POST':
78  if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
79  $upload_handler->delete();
80  } else {
81  $upload_handler->post();
82  }
83  break;
84  case 'DELETE':
85  $upload_handler->delete();
86  break;
87  default:
88  header('HTTP/1.0 405 Method Not Allowed');
89  exit;
90 }
91 
92 $db->close();
This class is used to manage file upload using ajax.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1440