Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
vMap
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open source
vMap
Commits
f191f1c1
Commit
f191f1c1
authored
6 years ago
by
Armand Bahi
Browse files
Options
Downloads
Patches
Plain Diff
Fournit une structure identique à l'upload de fichier dans $_FILES
parent
629c49e2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
vas/rest/index.phtml
+73
-21
73 additions, 21 deletions
vas/rest/index.phtml
with
73 additions
and
21 deletions
vas/rest/index.phtml
+
73
−
21
View file @
f191f1c1
...
@@ -63,24 +63,13 @@ if (!empty($boundary)) {
...
@@ -63,24 +63,13 @@ if (!empty($boundary)) {
$aFilenamePathInfo
=
pathinfo
(
$filename
);
$aFilenamePathInfo
=
pathinfo
(
$filename
);
$filename
=
$aFilenamePathInfo
[
'filename'
]
.
'.'
.
$aFilenamePathInfo
[
'extension'
];
$filename
=
$aFilenamePathInfo
[
'filename'
]
.
'.'
.
$aFilenamePathInfo
[
'extension'
];
// Multiples documents
// [DEPRECATED]
if
(
substr
(
$name
,
-
2
)
==
'[]'
)
{
$_FILES
[
substr
(
$name
,
0
,
-
2
)][]
=
array
(
"file"
=>
substr
(
$body
,
0
,
strlen
(
$body
)
-
2
),
"name"
=>
$filename
);
}
// Documents simples
else
{
$_PUTDATA
[
$name
.
"_file"
]
=
substr
(
$body
,
0
,
strlen
(
$body
)
-
2
);
$_PUTDATA
[
$name
.
"_file"
]
=
substr
(
$body
,
0
,
strlen
(
$body
)
-
2
);
$_PUTDATA
[
$name
.
"_name"
]
=
$filename
;
$_PUTDATA
[
$name
.
"_name"
]
=
$filename
;
// Utilisation de $_FILES
// Extrait les fichiers de aValues dans $_FILES
$_FILES
[
$name
]
=
array
(
extractPutFileStruct
(
$name
,
$filename
,
substr
(
$body
,
0
,
strlen
(
$body
)
-
2
),
$properties
);
"file"
=>
substr
(
$body
,
0
,
strlen
(
$body
)
-
2
),
"name"
=>
$filename
);
}
}
else
{
}
else
{
$_PUTDATA
[
$name
]
=
substr
(
$body
,
0
,
strlen
(
$body
)
-
2
);
$_PUTDATA
[
$name
]
=
substr
(
$body
,
0
,
strlen
(
$body
)
-
2
);
}
}
...
@@ -88,13 +77,12 @@ if (!empty($boundary)) {
...
@@ -88,13 +77,12 @@ if (!empty($boundary)) {
}
}
}
}
error_log
(
'$_POST: '
.
print_r
(
$_POST
,
true
));
error_log
(
'$_FILES: '
.
print_r
(
$_FILES
,
true
));
$aParamsJson
=
json_decode
(
file_get_contents
(
'php://input'
),
true
);
$aParamsJson
=
json_decode
(
file_get_contents
(
'php://input'
),
true
);
if
(
$_PUTDATA
!=
null
)
{
if
(
$_PUTDATA
!=
null
)
{
$aValues
=
array_merge
(
$_REQUEST
,
$_PUTDATA
);
$aValues
=
array_merge
(
$_REQUEST
,
$_PUTDATA
);
}
else
{
}
else
{
// Réorganise $_FILES pour les fichiers multiples
extractPostFileStruct
();
$aValues
=
$_REQUEST
;
$aValues
=
$_REQUEST
;
}
}
if
(
$aParamsJson
!=
null
)
{
if
(
$aParamsJson
!=
null
)
{
...
@@ -207,5 +195,69 @@ function customErrorHandler ($errno, $errstr, $errfile, $errline, $context){
...
@@ -207,5 +195,69 @@ function customErrorHandler ($errno, $errstr, $errfile, $errline, $context){
}
}
}
}
/**
* Extract the PUT upload files structure and put them into $_FILES
*
* @param {string} $sField Field name
* @param {string} $sFileName File name
* @param {string} $sFileContent File content
* @param {array} $properties properties
*/
function
extractPutFileStruct
(
$sField
,
$sFileName
,
$sFileContent
,
$properties
)
{
// Crée un fichier dans tmp
$sTmpFile
=
$properties
[
'extract_dir'
]
.
"/"
.
getUniqRandomId
();
$oFile
=
fopen
(
$sTmpFile
,
'w+'
);
if
(
!
$oFile
){
writeToErrorLog
(
"Can't open file in "
.
$properties
[
'extract_dir'
]);
return
null
;
}
else
{
fwrite
(
$oFile
,
$sFileContent
);
fclose
(
$oFile
);
$aFileStruc
=
array
(
"name"
=>
$sFileName
,
"tmp_name"
=>
$sTmpFile
,
"error"
=>
"0"
,
"size"
=>
filesize
(
$sTmpFile
)
);
}
// Fichiers simples
if
(
substr
(
$sField
,
-
2
)
!=
'[]'
)
{
$_FILES
[
$sField
]
=
$aFileStruc
;
}
// Fichiers multiples
if
(
substr
(
$sField
,
-
2
)
==
'[]'
)
{
$_FILES
[
substr
(
$sField
,
0
,
-
2
)][]
=
$aFileStruc
;
}
}
/**
* Extract the POST upload multiple files into a common structure
*
*/
function
extractPostFileStruct
()
{
foreach
(
$_FILES
as
$key
=>
$value
)
{
// Fichier multiple
if
(
is_array
(
$value
[
'name'
]))
{
$aFiles
=
[];
for
(
$i
=
0
;
$i
<
count
(
$value
[
'name'
]);
$i
++
)
{
$aFile
=
[];
foreach
(
$value
as
$key2
=>
$value2
)
{
$aFile
[
$key2
]
=
$value
[
$key2
][
$i
];
}
array_push
(
$aFiles
,
$aFile
);
}
$_FILES
[
$key
]
=
$aFiles
;
}
}
}
include
(
"index.vhtml"
);
include
(
"index.vhtml"
);
?>
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment