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:
Damian Mooyman 2015-06-09 13:22:10 +12:00
commit b42ddd107c
3 changed files with 29 additions and 14 deletions

View File

@ -273,9 +273,11 @@ class Upload extends Controller {
/**
* Clear out all errors (mostly set by {loadUploaded()})
* including the validator's errors
*/
public function clearErrors() {
$this->errors = array();
$this->validator->clearErrors();
}
/**
@ -345,6 +347,13 @@ class Upload_Validator {
return $this->errors;
}
/**
* Clear out all errors
*/
public function clearErrors() {
$this->errors = array();
}
/**
* Set information about temporary file produced by PHP.
* @param array $tmpFile

View File

@ -1223,20 +1223,25 @@ class UploadField extends FileField {
$name = $this->getName();
$postVars = $request->postVar($name);
// Save the temporary file into a File object
// Extract uploaded files from Form data
$uploadedFiles = $this->extractUploadedFileData($postVars);
$firstFile = reset($uploadedFiles);
$file = $this->saveTemporaryFile($firstFile, $error);
if(empty($file)) {
$return = array('error' => $error);
} else {
$return = $this->encodeFileAttributes($file);
$return = array();
// Save the temporary files into a File objects
// and save data/error on a per file basis
foreach ($uploadedFiles as $tempFile) {
$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
$response = new SS_HTTPResponse(Convert::raw2json(array($return)));
$response = new SS_HTTPResponse(Convert::raw2json($return));
$response->addHeader('Content-Type', 'text/plain');
if (!empty($return['error'])) $response->setStatusCode(403);
return $response;
}

View File

@ -167,8 +167,9 @@ class UploadFieldTest extends FunctionalTest {
'UploadFieldTest_Controller/Form/field/AllowedExtensionsField/upload',
array('AllowedExtensionsField' => $this->getUploadFile($invalidFile))
);
$this->assertTrue($response->isError());
$this->assertContains('Extension is not allowed', $response->getBody());
$response = json_decode($response->getBody(), true);
$this->assertTrue(array_key_exists('error', $response[0]));
$this->assertContains('Extension is not allowed', $response[0]['error']);
$validFile = 'valid.txt';
$_FILES = array('AllowedExtensionsField' => $this->getUploadFile($validFile));
@ -176,8 +177,8 @@ class UploadFieldTest extends FunctionalTest {
'UploadFieldTest_Controller/Form/field/AllowedExtensionsField/upload',
array('AllowedExtensionsField' => $this->getUploadFile($validFile))
);
$this->assertFalse($response->isError());
$this->assertNotContains('Extension is not allowed', $response->getBody());
$response = json_decode($response->getBody(), true);
$this->assertFalse(array_key_exists('error', $response[0]));
}
/**