25if (!defined(
'NOTOKENRENEWAL')) {
26 define(
'NOTOKENRENEWAL',
'1');
28if (!defined(
'NOREQUIREMENU')) {
29 define(
'NOREQUIREMENU',
'1');
31if (!defined(
'NOREQUIREHTML')) {
32 define(
'NOREQUIREHTML',
'1');
34if (!defined(
'NOREQUIREAJAX')) {
35 define(
'NOREQUIREAJAX',
'1');
37if (!defined(
'NOREQUIRESOC')) {
38 define(
'NOREQUIRESOC',
'1');
41if (!defined(
"NOLOGIN")) {
42 define(
"NOLOGIN",
'1');
47require
'../../main.inc.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
58$action =
GETPOST(
'action',
'aZ09');
60$module =
GETPOST(
'module',
'aZ09arobase');
62$flowFilename =
GETPOST(
'flowFilename',
'alpha');
63$flowIdentifier =
GETPOST(
'flowIdentifier',
'alpha');
64$flowChunkNumber =
GETPOST(
'flowChunkNumber',
'alpha');
65$flowChunkSize =
GETPOST(
'flowChunkSize',
'alpha');
66$flowTotalSize =
GETPOST(
'flowTotalSize',
'alpha');
68$result =
restrictedArea($user, $module, 0,
'',
'',
'fk_soc',
'rowid', 0, 1);
70if ($action !=
'upload') {
74if (!empty(
$conf->$module->dir_temp)) {
75 $upload_dir =
$conf->$module->dir_temp;
77 httponly_accessforbidden(
"Param module does not has a dir_temp directory. Module does not exists or is not activated.");
88if (!empty($upload_dir)) {
89 $temp_dir = $upload_dir.
'/'.$flowIdentifier;
91 $temp_dir = DOL_DATA_ROOT.
'/'.$module.
'/temp/'.$flowIdentifier;
92 $upload_dir = DOL_DATA_ROOT.
'/'.$module.
'/temp/';
95if ($module !=
"test" && !isModEnabled($module)) {
96 echo json_encode(
"The module ".$module.
" is not enabled");
97 header(
"HTTP/1.0 400");
101if ($_SERVER[
'REQUEST_METHOD'] ===
'GET') {
102 $chunk_file = $temp_dir.
'/'.$flowFilename.
'.part'.$flowChunkNumber;
103 if (file_exists($chunk_file)) {
104 header(
"HTTP/1.0 200 Ok");
106 header(
"HTTP/1.0 404 Not Found");
110 if (file_exists($upload_dir.
'/'.$flowFilename)) {
111 echo json_encode(
'File '.$flowIdentifier.
' was already uploaded');
112 header(
"HTTP/1.0 200 Ok");
114 } elseif (!empty($_FILES)) {
115 foreach ($_FILES as $file) {
117 if ($file[
'error'] != 0) {
118 dol_syslog(
'error '.$file[
'error'].
' in file '.$flowFilename);
124 $dest_file = $temp_dir.
'/'.$flowFilename.
'.part'.$flowChunkNumber;
133 dol_syslog(
'Error saving (move_uploaded_file) chunk '.$flowChunkNumber.
' for file '.$flowFilename);
136 $result = createFileFromChunks($temp_dir, $upload_dir, $flowFilename, $flowChunkSize, $flowTotalSize);
142 echo json_encode(
'File '.$flowIdentifier.
' uploaded');
144 echo json_encode(
'Error while uploading file '.$flowIdentifier);
158function createFileFromChunks($temp_dir, $upload_dir, $fileName, $chunkSize, $totalSize)
165 foreach ($files as $file) {
166 if (stripos($file[
"name"], $fileName) !==
false) {
173 if ($total_files * (
float) $chunkSize >= ((
float) $totalSize - (
float) $chunkSize + 1)) {
175 if (($fp = fopen($upload_dir.
'/'.$fileName,
'w')) !==
false) {
176 for ($i = 1; $i <= $total_files; $i++) {
177 fwrite($fp, file_get_contents($temp_dir.
'/'.$fileName.
'.part'.$i));
182 dol_syslog(
'cannot create the destination file');
188 @rename($temp_dir, $temp_dir.
'_UNUSED');
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Check validity of a file upload from an GUI page, and move it to its final destination.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.