mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #3499 from colymba/ie-multi-file-upload-fix
FIX #3458 iframe transport multi file upload FIX #3343, FIX #3148
This commit is contained in:
commit
b42ddd107c
@ -273,9 +273,11 @@ class Upload extends Controller {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear out all errors (mostly set by {loadUploaded()})
|
* Clear out all errors (mostly set by {loadUploaded()})
|
||||||
|
* including the validator's errors
|
||||||
*/
|
*/
|
||||||
public function clearErrors() {
|
public function clearErrors() {
|
||||||
$this->errors = array();
|
$this->errors = array();
|
||||||
|
$this->validator->clearErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -345,6 +347,13 @@ class Upload_Validator {
|
|||||||
return $this->errors;
|
return $this->errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear out all errors
|
||||||
|
*/
|
||||||
|
public function clearErrors() {
|
||||||
|
$this->errors = array();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set information about temporary file produced by PHP.
|
* Set information about temporary file produced by PHP.
|
||||||
* @param array $tmpFile
|
* @param array $tmpFile
|
||||||
|
@ -1223,20 +1223,25 @@ class UploadField extends FileField {
|
|||||||
$name = $this->getName();
|
$name = $this->getName();
|
||||||
$postVars = $request->postVar($name);
|
$postVars = $request->postVar($name);
|
||||||
|
|
||||||
// Save the temporary file into a File object
|
// Extract uploaded files from Form data
|
||||||
$uploadedFiles = $this->extractUploadedFileData($postVars);
|
$uploadedFiles = $this->extractUploadedFileData($postVars);
|
||||||
$firstFile = reset($uploadedFiles);
|
$return = array();
|
||||||
$file = $this->saveTemporaryFile($firstFile, $error);
|
|
||||||
if(empty($file)) {
|
// Save the temporary files into a File objects
|
||||||
$return = array('error' => $error);
|
// and save data/error on a per file basis
|
||||||
} else {
|
foreach ($uploadedFiles as $tempFile) {
|
||||||
$return = $this->encodeFileAttributes($file);
|
$file = $this->saveTemporaryFile($tempFile, $error);
|
||||||
|
if(empty($file)) {
|
||||||
|
array_push($return, array('error' => $error));
|
||||||
|
} else {
|
||||||
|
array_push($return, $this->encodeFileAttributes($file));
|
||||||
|
}
|
||||||
|
$this->upload->clearErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format response with json
|
// Format response with json
|
||||||
$response = new SS_HTTPResponse(Convert::raw2json(array($return)));
|
$response = new SS_HTTPResponse(Convert::raw2json($return));
|
||||||
$response->addHeader('Content-Type', 'text/plain');
|
$response->addHeader('Content-Type', 'text/plain');
|
||||||
if (!empty($return['error'])) $response->setStatusCode(403);
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,8 +167,9 @@ class UploadFieldTest extends FunctionalTest {
|
|||||||
'UploadFieldTest_Controller/Form/field/AllowedExtensionsField/upload',
|
'UploadFieldTest_Controller/Form/field/AllowedExtensionsField/upload',
|
||||||
array('AllowedExtensionsField' => $this->getUploadFile($invalidFile))
|
array('AllowedExtensionsField' => $this->getUploadFile($invalidFile))
|
||||||
);
|
);
|
||||||
$this->assertTrue($response->isError());
|
$response = json_decode($response->getBody(), true);
|
||||||
$this->assertContains('Extension is not allowed', $response->getBody());
|
$this->assertTrue(array_key_exists('error', $response[0]));
|
||||||
|
$this->assertContains('Extension is not allowed', $response[0]['error']);
|
||||||
|
|
||||||
$validFile = 'valid.txt';
|
$validFile = 'valid.txt';
|
||||||
$_FILES = array('AllowedExtensionsField' => $this->getUploadFile($validFile));
|
$_FILES = array('AllowedExtensionsField' => $this->getUploadFile($validFile));
|
||||||
@ -176,8 +177,8 @@ class UploadFieldTest extends FunctionalTest {
|
|||||||
'UploadFieldTest_Controller/Form/field/AllowedExtensionsField/upload',
|
'UploadFieldTest_Controller/Form/field/AllowedExtensionsField/upload',
|
||||||
array('AllowedExtensionsField' => $this->getUploadFile($validFile))
|
array('AllowedExtensionsField' => $this->getUploadFile($validFile))
|
||||||
);
|
);
|
||||||
$this->assertFalse($response->isError());
|
$response = json_decode($response->getBody(), true);
|
||||||
$this->assertNotContains('Extension is not allowed', $response->getBody());
|
$this->assertFalse(array_key_exists('error', $response[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user