commit dec069b9edec98e5e541860dd5cf625e75e3140a
parent a1e111ebf1057259fa3739c432d6eba495002528
Author: Felicitus <felicitus@felicitus.org>
Date: Wed, 4 Jul 2012 19:27:24 +0200
Final fix for issue #220
Diffstat:
3 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/src/backend/PartKeepr/TempFile/TempFileService.php b/src/backend/PartKeepr/TempFile/TempFileService.php
@@ -10,12 +10,28 @@ class TempFileService extends Service {
public function upload () {
$tmpFile = new TempUploadedFile();
- if (array_key_exists("userfile", $_FILES) && file_exists($_FILES["userfile"]["tmp_name"])) {
- $file = $_FILES['userfile']['tmp_name'];
- $filename = $_FILES['userfile']['name'];
+ if (array_key_exists("userfile", $_FILES))
+ {
+ switch ($_FILES["userfile"]["error"]) {
+ case 1:
+ case 2:
+ throw new \Exception("Uploaded file is too big");
+ break;
+ case 3:
+ throw new \Exception("File was only partially uploaded. Report this as a bug.");
+ break;
+ default:
+ if (file_exists($_FILES["userfile"]["tmp_name"])) {
+ $file = $_FILES['userfile']['tmp_name'];
+ $filename = $_FILES['userfile']['name'];
+
+ $tmpFile->replace($file);
+ $tmpFile->setOriginalFilename(basename($filename));
+ } else {
+ throw new \Exception("Unknown error occured while uploading the file");
+ }
+ }
- $tmpFile->replace($file);
- $tmpFile->setOriginalFilename(basename($filename));
} elseif (array_key_exists("url", $_REQUEST)) {
$tmpFile->replaceFromURL($_REQUEST["url"]);
} else {
diff --git a/src/backend/PartKeepr/UploadedFile/UploadedFile.php b/src/backend/PartKeepr/UploadedFile/UploadedFile.php
@@ -139,7 +139,11 @@ abstract class UploadedFile extends BaseEntity implements Serializable {
$data = curl_exec($curl);
if ($data === false) {
- throw new \Exception("replaceFromURL error: ".curl_error($curl));
+ $curlError = curl_error($curl);
+ // Strip ANY tags from the error message. curl tends to spit out <url> is not valid, which then
+ // confuses the error message parser on the client side.
+ $curlError = str_replace(array(">", "<"), "", $curlError);
+ throw new \Exception("replaceFromURL error: ".$curlError);
}
curl_close($curl);
diff --git a/src/frontend/js/Dialogs/FileUploadDialog.js b/src/frontend/js/Dialogs/FileUploadDialog.js
@@ -25,8 +25,6 @@ Ext.define('PartKeepr.FileUploadDialog', {
handler: Ext.bind(function() {
var form = this.form.getForm();
- var values = form.getValues();
-
if (this.fileField.getValue() === "" && this.urlField.getValue() === "") {
Ext.Msg.alert(i18n("Error"), i18n("Please select a file to upload or enter an URL"));
return;
@@ -45,7 +43,6 @@ Ext.define('PartKeepr.FileUploadDialog', {
this.close();
},this),
failure: function(form, action) {
-
var data = Ext.decode(action.response.responseText);
request = {