From 80405fe18d8b551ca95af86e30e1855f9d864e4f Mon Sep 17 00:00:00 2001 From: nbm Date: Sat, 28 May 2005 11:30:34 +0000 Subject: [PATCH] Give better error messages when uploads fail - detect if post_max_size or upload_max_filesize have been violated. --- presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php | 29 ++++++++++++++++++++++++++--- presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc | 2 ++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php b/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php index 698e5d5..d39fe28 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php @@ -32,7 +32,6 @@ require_once("../../../../config/dmsDefaults.php"); KTUtil::extractGPC('fFolderID', 'fStore', 'fDocumentTypeID', 'fName', 'fDependantDocumentID'); - if (!checkSession()) { exit(0); } @@ -54,6 +53,20 @@ require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc" require_once("addDocumentUI.inc"); require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/store.inc"); +$postExpected = KTUtil::arrayGet($_REQUEST, "postExpected"); +$postReceived = KTUtil::arrayGet($_REQUEST, "postReceived"); +if (!is_null($postExpected) && is_null($postReceived)) { + // A post was to be initiated by the client, but none was received. + // This means post_max_size was violated. + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); + $oPatternCustom = & new PatternCustom(); + $errorMessage = _("You tried to upload a file that is larger than the PHP post_max_size setting."); + $oPatternCustom->setHtml(getStatusPage($fFolderID, $errorMessage . "rootUrl/control.php?action=browse&fFolderID=$fFolderID\">")); + $main->setCentralPayload($oPatternCustom); + $main->render(); + exit(0); +} + if (!isset($fFolderID)) { //no folder id was set when coming to this page, //so display an error message @@ -84,7 +97,7 @@ if (!isset($fStore)) { $oPatternCustom = & new PatternCustom(); $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentTypeID, $fDependantDocumentID)); $main->setCentralPayload($oPatternCustom); - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID" . + $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&postExpected=1" . (isset($fDependantDocumentID) ? "&fDependantDocumentID=$fDependantDocumentID" : "") . (isset($fDocumentTypeID) ? "&fDocumentTypeID=$fDocumentTypeID" : "")); $main->setFormEncType("multipart/form-data"); @@ -110,7 +123,17 @@ if (!((strlen($_FILES['fFile']['name']) > 0) && $_FILES['fFile']['size'] > 0)) { // no uploaded file require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); - $oPatternCustom->setHtml(getStatusPage($fFolderID, _("You did not select a valid document to upload") . "rootUrl/control.php?action=addDocument&fFolderID=$fFolderID&fDocumentTypeID=$fDocumentTypeID\">")); + $message = _("You did not select a valid document to upload"); + + $errors = array( + 1 => _("The uploaded file is larger than the PHP upload_max_filesize setting"), + 2 => _("The uploaded file is larger than the MAX_FILE_SIZE directive that was specified in the HTML form"), + 3 => _("The uploaded file was not fully uploaded to KnowledgeTree"), + 4 => _("No file was selected to be uploaded to KnowledgeTree"), + 6 => _("An internal error occurred receiving the uploaded document"), + ); + $message = KTUtil::arrayGet($errors, $_FILES['fFile']['error'], $message); + $oPatternCustom->setHtml(getStatusPage($fFolderID, $message . "rootUrl/control.php?action=addDocument&fFolderID=$fFolderID&fDocumentTypeID=$fDocumentTypeID\">")); $main->setCentralPayload($oPatternCustom); $main->render(); exit(0); diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc b/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc index c90236c..46bd7d5 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc @@ -178,6 +178,7 @@ function getPage($iFolderID, $iDocumentTypeID, $iDependantDocumentID = null, $sM $sToRender .= getMetaDataForm($iFolderID, $iDocumentTypeID); $sActionButtons = ""; $sToRender .= ""; + $sToRender .= ""; $sActionButtons .= generateControllerLink("addDocument", $sQueryString , "") . generateControllerLink("browse", "fFolderID=$iFolderID", ""); @@ -192,6 +193,7 @@ function getPage($iFolderID, $iDocumentTypeID, $iDependantDocumentID = null, $sM $sToRender .= getDocumentType($iFolderID, $iDocumentTypeID, $iDependantDocumentID); $sActionButtons .= generateControllerLink("browse", "fFolderID=$iFolderID", ""); $sActionButtons .= ""; + $sToRender .= ""; $sToRender .= "\n"; $sToRender .= ""; -- libgit2 0.21.4
$sActionButtons