commit 30bfc94194d1f538e0f4af005212d54ffae57da4
parent ce2e0d91e7ad83cd25dc9f633cdb8c6ab47af00b
Author: Felicitus <felicitus@felicitus.org>
Date: Sat, 24 Nov 2012 06:46:45 +0100
Fixes a bug, probably with never PHP versions, or I did mess something up. No matter what caused the problem, it's fixed now.
Mainly this bug is caused by an empty $_FILES array on the PHP side, even if no file was specified. We now check if $_FILES["userfile"]["name"] is not equal to "", and only throw exceptions if it's nonempty. That re-enables the file uploads via URL again.
This fixes bug #261.
Diffstat:
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/backend/PartKeepr/TempFile/TempFileService.php b/src/backend/PartKeepr/TempFile/TempFileService.php
@@ -7,10 +7,27 @@ use PartKeepr\PartKeepr;
class TempFileService extends Service {
- public function upload () {
+ /**
+ * Handles file uploads.
+ *
+ * This method can handle one upload per call; the file data needs to be in the "userfile" form variable - OR - be
+ * passed as "url" parameter, in which case this method will download the remote file.
+ *
+ * @return array An array containing the following information:
+ * - id: The id of the temporary file
+ * - extension: The extension of the temporary file
+ * - size: The size of the temporary file
+ * - originalFilename: The original file name
+ * @throws \Exception If something went wrong (yes, this needs refactoring!)
+ *
+ * @todo Refactoring this method needs to be done - it's bad, but mostly bad due to the bad handling of the $_FILES
+ * array. Probably some wrapper method would help?
+ */
+ public function upload () {
$tmpFile = new TempUploadedFile();
-
- if (array_key_exists("userfile", $_FILES) && array_key_exists("error", $_FILES["userfile"]))
+
+ if (array_key_exists("userfile", $_FILES) && array_key_exists("error", $_FILES["userfile"]) &&
+ $_FILES["userfile"]["name"] != "")
{
switch ($_FILES["userfile"]["error"]) {
case 1:
@@ -43,7 +60,7 @@ class TempFileService extends Service {
return array("id" => $tmpFile->getId(), "extension" => $tmpFile->getExtension(), "size" => $tmpFile->getSize(), "originalFilename" => $tmpFile->getOriginalFilename());
}
-
+
/**
* Receives a file via the service call.
*