dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
25if (!defined('NOREQUIREMENU')) {
26 define('NOREQUIREMENU', '1'); // If there is no menu to show
27}
28if (!defined('NOREQUIREHTML')) {
29 define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
30}
31if (!defined('NOREQUIREAJAX')) {
32 define('NOREQUIREAJAX', '1');
33}
34if (!defined('NOREQUIRESOC')) {
35 define('NOREQUIRESOC', '1');
36}
37
38// Load Dolibarr environment
39require '../../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/fileupload.class.php'; // Class to upload common files
41require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
43
52$id = GETPOSTINT('fk_element');
53$element = GETPOST('element', 'alpha'); // 'myobject' (myobject=mymodule) or 'myobject@mymodule' or 'myobject_mysubobject' (myobject=mymodule)
54$elementupload = $element;
55
56// Load object according to $id and $element
57$object = fetchObjectByElement($id, $element);
58
59$module = $object->module;
60$element = $object->element;
61
62$usesublevelpermission = ($module != $element ? $element : '');
63if ($usesublevelpermission && !$user->hasRight($module, $element)) { // There is no permission on object defined, we will check permission on module directly
64 $usesublevelpermission = '';
65}
66
67//print 'fileupload.php: '.$object->id.' - '.$object->module.' - '.$object->element.' - '.$object->table_element.' - '.$usesublevelpermission."\n";
68
69// Security check
70if (!empty($user->socid)) {
71 $socid = $user->socid;
72 if (!empty($object->socid) && $socid != $object->socid) {
73 httponly_accessforbidden("Access on object not allowed for this external user."); // This includes the exit.
74 }
75}
76
77$result = restrictedArea($user, $object->module, $object, $object->table_element, $usesublevelpermission, 'fk_soc', 'rowid', 0, 1); // Call with mode return
78if (!$result) {
79 httponly_accessforbidden('Not allowed by restrictArea (module='.$object->module.' table_element='.$object->table_element.')');
80}
81
82
83/*
84 * View
85 */
86
88
89header('Pragma: no-cache');
90header('Cache-Control: no-store, no-cache, must-revalidate');
91header('Content-Disposition: inline; filename="files.json"');
92header('X-Content-Type-Options: nosniff');
93header('Access-Control-Allow-Origin: '.getRootURLFromURL(DOL_MAIN_URL_ROOT));
94header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE');
95header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size');
96
97switch ($_SERVER['REQUEST_METHOD']) {
98 case 'OPTIONS':
99 break;
100 /*case 'HEAD':
101 case 'GET':
102 $upload_handler->get();
103 break;
104 */
105 case 'POST':
106 $upload_handler = new FileUpload(null, $id, $elementupload);
107
108 /*if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
109 $file = GETPOST('file');
110 $upload_handler->delete($file);
111 } else {*/
112 $upload_handler->post();
113 // Note: even if this return an error on 1 file in post(), we will return http code 200 because error must be managed by the caller (some files may be ok and some in error)
114 //}
115 break;
116 /*case 'DELETE':
117 $file = GETPOST('file');
118 $upload_handler->delete($file);
119 break;*/
120 default:
121 header('HTTP/1.0 405 Method Not Allowed');
122 exit;
123}
124
125$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
This class is used to manage file upload using ajax.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
fetchObjectByElement($element_id, $element_type, $element_ref='', $useCache=0, $maxCacheByType=10)
Fetch an object from its id and element_type Inclusion of classes is automatic.
getRootURLFromURL($url)
Function root url from a long url For example: https://www.abc.mydomain.com/dir/page....
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.