dolibarr 20.0.0
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
24if (!defined('NOREQUIREMENU')) {
25 define('NOREQUIREMENU', '1'); // If there is no menu to show
26}
27if (!defined('NOREQUIREHTML')) {
28 define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
29}
30if (!defined('NOREQUIREAJAX')) {
31 define('NOREQUIREAJAX', '1');
32}
33if (!defined('NOREQUIRESOC')) {
34 define('NOREQUIRESOC', '1');
35}
36
37// Load Dolibarr environment
38require '../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/fileupload.class.php'; // Class to upload common files
40require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
42
43$id = GETPOSTINT('fk_element');
44$element = GETPOST('element', 'alpha'); // 'myobject' (myobject=mymodule) or 'myobject@mymodule' or 'myobject_mysubobject' (myobject=mymodule)
45$elementupload = $element;
46
47// Load object according to $id and $element
48$object = fetchObjectByElement($id, $element);
49
50$module = $object->module;
51$element = $object->element;
52
53$usesublevelpermission = ($module != $element ? $element : '');
54if ($usesublevelpermission && !$user->hasRight($module, $element)) { // There is no permission on object defined, we will check permission on module directly
55 $usesublevelpermission = '';
56}
57
58//print 'fileupload.php: '.$object->id.' - '.$object->module.' - '.$object->element.' - '.$object->table_element.' - '.$usesublevelpermission."\n";
59
60// Security check
61if (!empty($user->socid)) {
62 $socid = $user->socid;
63 if (!empty($object->socid) && $socid != $object->socid) {
64 httponly_accessforbidden("Access on object not allowed for this external user."); // This includes the exit.
65 }
66}
67
68$result = restrictedArea($user, $object->module, $object, $object->table_element, $usesublevelpermission, 'fk_soc', 'rowid', 0, 1); // Call with mode return
69if (!$result) {
70 httponly_accessforbidden('Not allowed by restrictArea (module='.$object->module.' table_element='.$object->table_element.')');
71}
72
73
74/*
75 * View
76 */
77
79
80header('Pragma: no-cache');
81header('Cache-Control: no-store, no-cache, must-revalidate');
82header('Content-Disposition: inline; filename="files.json"');
83header('X-Content-Type-Options: nosniff');
84header('Access-Control-Allow-Origin: '.getRootURLFromURL(DOL_MAIN_URL_ROOT));
85header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE');
86header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size');
87
88switch ($_SERVER['REQUEST_METHOD']) {
89 case 'OPTIONS':
90 break;
91 /*case 'HEAD':
92 case 'GET':
93 $upload_handler->get();
94 break;
95 */
96 case 'POST':
97 $upload_handler = new FileUpload(null, $id, $elementupload);
98
99 /*if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
100 $file = GETPOST('file');
101 $upload_handler->delete($file);
102 } else {*/
103 $upload_handler->post();
104 // 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)
105 //}
106 break;
107 /*case 'DELETE':
108 $file = GETPOST('file');
109 $upload_handler->delete($file);
110 break;*/
111 default:
112 header('HTTP/1.0 405 Method Not Allowed');
113 exit;
114}
115
116$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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.