AIRAVATA-1397 Display error when file upload too big Throws and displays error when file upload exceeds upload_max_filesize or any other error with uploading the file.
Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/bc6ded07 Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/bc6ded07 Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/bc6ded07 Branch: refs/heads/dreg-gateway Commit: bc6ded07f8067b86846cd171fd8eda27f7d0ccac Parents: 6cdc2a1 Author: Marcus Christie <machris...@apache.org> Authored: Wed Jan 18 15:18:38 2017 -0500 Committer: Marcus Christie <machris...@apache.org> Committed: Wed Jan 18 15:18:38 2017 -0500 ---------------------------------------------------------------------- app/controllers/ExperimentController.php | 17 +++++++++++++++-- app/libraries/ExperimentUtilities.php | 12 ++++++++++++ app/views/experiment/create.blade.php | 7 +++++++ app/views/experiment/edit.blade.php | 6 ++++++ 4 files changed, 40 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/bc6ded07/app/controllers/ExperimentController.php ---------------------------------------------------------------------- diff --git a/app/controllers/ExperimentController.php b/app/controllers/ExperimentController.php index 7bfd8c5..6f4364f 100755 --- a/app/controllers/ExperimentController.php +++ b/app/controllers/ExperimentController.php @@ -89,7 +89,13 @@ class ExperimentController extends BaseController } } else if (isset($_POST['save']) || isset($_POST['launch'])) { - $expId = ExperimentUtilities::create_experiment(); + try { + $expId = ExperimentUtilities::create_experiment(); + } catch (Exception $ex) { + Log::error("Failed to create experiment!"); + Log::error($ex); + return Redirect::to("experiment/create")->with("error-message", "Failed to create experiment: " . $ex->getMessage()); + } if (isset($_POST['launch']) && $expId) { ExperimentUtilities::launch_experiment($expId); @@ -354,7 +360,14 @@ class ExperimentController extends BaseController public function editSubmit() { $experiment = ExperimentUtilities::get_experiment(Input::get('expId')); // update local experiment variable - $updatedExperiment = ExperimentUtilities::apply_changes_to_experiment($experiment, Input::all()); + try { + $updatedExperiment = ExperimentUtilities::apply_changes_to_experiment($experiment, Input::all()); + } catch (Exception $ex) { + $errMessage = "Failed to update experiment: " . $ex->getMessage(); + Log::error($errMessage); + Log::error($ex); + return Redirect::to("experiment/edit?expId=" . urlencode(Input::get('expId')))->with("error-message", $errMessage); + } if(Config::get('pga_config.airavata')["data-sharing-enabled"]){ if (SharingUtilities::userCanWrite(Session::get("username"), Input::get('expId'), ResourceType::EXPERIMENT)) { http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/bc6ded07/app/libraries/ExperimentUtilities.php ---------------------------------------------------------------------- diff --git a/app/libraries/ExperimentUtilities.php b/app/libraries/ExperimentUtilities.php index 0b89df1..005ddee 100755 --- a/app/libraries/ExperimentUtilities.php +++ b/app/libraries/ExperimentUtilities.php @@ -396,7 +396,12 @@ class ExperimentUtilities } } elseif ($applicationInput->type == DataType::URI) { if ($_FILES[$applicationInput->sanitizedFormName]['name']) { + $file = $_FILES[$applicationInput->sanitizedFormName]; + if ($file['error'] != 0) { + throw new Exception("Failure occurred while uploading file '" + . $file['name'] . "'. File upload error code is " . $file['error'] . "."); + } // // move file to experiment data directory @@ -463,6 +468,13 @@ class ExperimentUtilities $uriList = ""; for($i=0; $i < count($_FILES['optInputFiles']['name']); $i++){ if(!empty($_FILES['optInputFiles']['name'][$i])){ + + // Check if there is an error with the upload (like if it exceeded upload_max_filesize) + if ($_FILES['optInputFiles']['error'][$i] != 0) { + throw new Exception("Failure occurred while uploading file '" + . $_FILES['optInputFiles']['name'][$i] . "'. File upload error code is " . $_FILES['optInputFiles']['error'][$i] . "."); + } + $filePath = ExperimentUtilities::$experimentPath . $_FILES['optInputFiles']['name'][$i]; // check if file already exists http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/bc6ded07/app/views/experiment/create.blade.php ---------------------------------------------------------------------- diff --git a/app/views/experiment/create.blade.php b/app/views/experiment/create.blade.php index 82687c0..87225d4 100755 --- a/app/views/experiment/create.blade.php +++ b/app/views/experiment/create.blade.php @@ -6,6 +6,13 @@ @stop @section('content') + +@if( Session::has("error-message" ) ) + <div class="alert alert-danger"> + {{{ Session::get("error-message") }}} + </div> +@endif + <div class="col-md-offset-3 col-md-6"> <h1>Create a new experiment</h1> http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/bc6ded07/app/views/experiment/edit.blade.php ---------------------------------------------------------------------- diff --git a/app/views/experiment/edit.blade.php b/app/views/experiment/edit.blade.php index 52e035b..00fd008 100755 --- a/app/views/experiment/edit.blade.php +++ b/app/views/experiment/edit.blade.php @@ -17,6 +17,12 @@ <div class="container"> + @if (Session::has("error-message")) + <div class="alert alert-danger"> + {{{ Session::get("error-message") }}} + </div> + @endif + <div class="col-md-offset-3 col-md-6"> <h1>Edit Experiment</h1>