Permalink
Browse files

Changing upload pre-processor to handle files already uploaded

  • Loading branch information...
1 parent ba7da6b commit 6564518c116f78e691e04e50b1e1eacda51bc172 @ghecquet ghecquet committed Jun 3, 2016
Showing with 24 additions and 12 deletions.
  1. +24 −12 core/src/plugins/uploader.html/class.SimpleUploadProcessor.php
@@ -68,14 +68,35 @@ public function preProcess(\Psr\Http\Message\ServerRequestInterface &$request, \
throw new \Pydio\Core\Exception\PydioException("Warning, missing headers!");
}
- if (isSet($serverData['HTTP_X_FILE_SIZE'])) {
- if ($serverData['CONTENT_LENGTH'] != $serverData['HTTP_X_FILE_SIZE']) {
+ // Setting the stream data
+ if (isset($serverData['HTTP_X_FILE_TMP_LOCATION'])) {
+ // The file has already been transferred
+
+ // Checking headers
+ if (!isset($serverData['HTTP_X_FILE_SIZE'])) {
exit('Warning, wrong headers');
}
+
+ // Setting the stream to point to the file location
+ $streamOrFile = $serverData['HTTP_X_FILE_TMP_LOCATION'];
+ $errorStatus = UPLOAD_ERR_OK;
+ } else {
+ // The file is the post data stream
+
+ // Checking headers
+ if (isSet($serverData['HTTP_X_FILE_SIZE'])) {
+ if ($serverData['CONTENT_LENGTH'] != $serverData['HTTP_X_FILE_SIZE']) {
+ exit('Warning, wrong headers');
+ }
+ }
+
+ // Setting the stream to point to the post data
+ $streamOrFile = array_shift($request->getUploadedFiles())->getStream();
+ $errorStatus = $streamOrFile->getError();
}
$fileNameH = $serverData['HTTP_X_FILE_NAME'];
- $fileSizeH = (int)$serverData['CONTENT_LENGTH'];
+ $fileSizeH = (int)$serverData['HTTP_X_FILE_SIZE'];
// Clean up dir name
if (dirname($httpVars["dir"]) == "/" && basename($httpVars["dir"]) == $fileNameH) {
@@ -84,15 +105,6 @@ public function preProcess(\Psr\Http\Message\ServerRequestInterface &$request, \
$this->logDebug("SimpleUpload::preProcess", $httpVars);
- if (isSet($serverData['HTTP_X_FILE_TMP_LOCATION'])) {
- // The file has already been uploaded to a tmp location
- $streamOrFile = $serverData['HTTP_X_FILE_TMP_LOCATION'];
- $errorStatus = UPLOAD_ERR_OK;
- } else {
- $streamOrFile = array_shift($request->getUploadedFiles())->getStream();
- $errorStatus = $streamOrFile->getError();
- }
-
// Update UploadedFile object built on input stream with file name and size
$uploadedFile = new \Zend\Diactoros\UploadedFile($streamOrFile, $fileSizeH, $errorStatus, TextEncoder::fromUTF8(basename($fileNameH)));

0 comments on commit 6564518

Please sign in to comment.