Permalink
Browse files

Allow upload via tmp location

  • Loading branch information...
1 parent 494a27b commit 7c96e81edec18394c4e4b22173a1f1f7839aca50 @ghecquet ghecquet committed Jun 2, 2016
@@ -1567,7 +1567,7 @@ protected function copyUploadedData($uploadData, $destination, $messages){
}
$output = fopen($destination, "w");
$sizeRead = 0;
- while ($sizeRead < intval($newFileSize)) {
+ while ($sizeRead > 0 && $sizeRead < intval($newFileSize)) {
$chunk = fread($input, 4096);
$sizeRead += strlen($chunk);
fwrite($output, $chunk, strlen($chunk));
@@ -57,36 +57,46 @@ public function preProcess(\Psr\Http\Message\ServerRequestInterface &$request, \
{
$httpVars = $request->getParsedBody();
$serverData = $request->getServerParams();
+
if (!isSet($httpVars["input_stream"]) || isSet($httpVars["force_post"])) {
+ // Nothing to do
return;
}
- $headersCheck = isset(
- $serverData['CONTENT_LENGTH'],
- $serverData['HTTP_X_FILE_NAME']
- ) ;
+ // Mandatory headers
+ if (!isset($serverData['CONTENT_LENGTH'], $serverData['HTTP_X_FILE_NAME'])) {
+ 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']) {
exit('Warning, wrong headers');
}
}
+
$fileNameH = $serverData['HTTP_X_FILE_NAME'];
- $fileSizeH = $serverData['CONTENT_LENGTH'];
+ $fileSizeH = (int)$serverData['CONTENT_LENGTH'];
+ // Clean up dir name
if (dirname($httpVars["dir"]) == "/" && basename($httpVars["dir"]) == $fileNameH) {
$httpVars["dir"] = "/";
}
+
$this->logDebug("SimpleUpload::preProcess", $httpVars);
- if ($headersCheck) {
- /** @var \Psr\Http\Message\UploadedFileInterface $uploadedFile */
- $uploadedFile = array_shift($request->getUploadedFiles());
- // Update UploadedFile object built on input stream with file name and size
- $uploadedFile = new \Zend\Diactoros\UploadedFile($uploadedFile->getStream(), $fileNameH, $uploadedFile->getError(), TextEncoder::fromUTF8(basename($fileNameH)));
- $request = $request->withUploadedFiles(["userfile_0" => $uploadedFile]);
+ 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 {
- throw new \Pydio\Core\Exception\PydioException("Warning, missing headers!");
+ $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)));
+
+ $request = $request->withUploadedFiles(["userfile_0" => $uploadedFile]);
}
/**

0 comments on commit 7c96e81

Please sign in to comment.