23 if (!defined(
'NOTOKENRENEWAL')) {
24 define(
'NOTOKENRENEWAL',
'1');
26 if (!defined(
'NOREQUIREMENU')) {
27 define(
'NOREQUIREMENU',
'1');
29 if (!defined(
'NOREQUIREHTML')) {
30 define(
'NOREQUIREHTML',
'1');
32 if (!defined(
'NOREQUIREAJAX')) {
33 define(
'NOREQUIREAJAX',
'1');
35 if (!defined(
'NOREQUIRESOC')) {
36 define(
'NOREQUIRESOC',
'1');
39 if (!defined(
"NOLOGIN")) {
40 define(
"NOLOGIN",
'1');
45 require
'../../main.inc.php';
46 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
48 $action =
GETPOST(
'action',
'aZ09');
49 $module =
GETPOST(
'module',
'aZ09');
50 $upload_dir =
GETPOST(
'upload_dir',
'alpha');
51 $flowFilename =
GETPOST(
'flowFilename',
'alpha');
52 $flowIdentifier =
GETPOST(
'flowIdentifier',
'alpha');
53 $flowChunkNumber =
GETPOST(
'flowChunkNumber',
'alpha');
54 $flowChunkSize =
GETPOST(
'flowChunkSize',
'alpha');
55 $flowTotalSize =
GETPOST(
'flowTotalSize',
'alpha');
67 if (!empty($upload_dir)) {
68 $temp_dir = $upload_dir.
'/'.$flowIdentifier;
70 $temp_dir = DOL_DATA_ROOT.
'/'.$module.
'/temp/'.$flowIdentifier;
71 $upload_dir = DOL_DATA_ROOT.
'/'.$module.
'/temp/';
75 echo json_encode(
"The module ".$module.
" is not enabled");
76 header(
"HTTP/1.0 400");
80 if ($_SERVER[
'REQUEST_METHOD'] ===
'GET') {
81 $chunk_file = $temp_dir.
'/'.$flowFilename.
'.part'.$flowChunkNumber;
82 if (file_exists($chunk_file)) {
83 header(
"HTTP/1.0 200 Ok");
85 header(
"HTTP/1.0 404 Not Found");
89 if (file_exists($upload_dir.
'/'.$flowFilename)) {
90 echo json_encode(
'File '.$flowIdentifier.
' was already uploaded');
91 header(
"HTTP/1.0 200 Ok");
93 } elseif (!empty($_FILES))
foreach ($_FILES as $file) {
95 if ($file[
'error'] != 0) {
96 dol_syslog(
'error '.$file[
'error'].
' in file '.$flowFilename);
102 $dest_file = $temp_dir.
'/'.$flowFilename.
'.part'.$flowChunkNumber;
111 dol_syslog(
'Error saving (move_uploaded_file) chunk '.$flowChunkNumber.
' for file '.$flowFilename);
114 $result = createFileFromChunks($temp_dir, $upload_dir, $flowFilename, $flowChunkSize, $flowTotalSize);
119 echo json_encode(
'File '.$flowIdentifier.
' uploaded');
121 echo json_encode(
'Error while uploading file '.$flowIdentifier);
135 function createFileFromChunks($temp_dir, $upload_dir, $fileName, $chunkSize, $totalSize)
142 foreach ($files as $file) {
143 if (stripos($file[
"name"], $fileName) !==
false) {
150 if ($total_files * $chunkSize >= ($totalSize - $chunkSize + 1)) {
152 if (($fp = fopen($upload_dir.
'/'.$fileName,
'w')) !==
false) {
153 for ($i=1; $i<=$total_files; $i++) {
154 fwrite($fp, file_get_contents($temp_dir.
'/'.$fileName.
'.part'.$i));
159 dol_syslog(
'cannot create the destination file');
165 @rename($temp_dir, $temp_dir.
'_UNUSED');
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_dir_list($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.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Make control on an uploaded file from an GUI page and move it to final destination.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
isModEnabled($module)
Is Dolibarr module enabled.
dol_is_dir($folder)
Test if filename is a directory.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)