Commit 80405fe18d8b551ca95af86e30e1855f9d864e4f
1 parent
3c461e4a
Give better error messages when uploads fail - detect if post_max_size
or upload_max_filesize have been violated. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3314 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
28 additions
and
3 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php
| ... | ... | @@ -32,7 +32,6 @@ |
| 32 | 32 | require_once("../../../../config/dmsDefaults.php"); |
| 33 | 33 | |
| 34 | 34 | KTUtil::extractGPC('fFolderID', 'fStore', 'fDocumentTypeID', 'fName', 'fDependantDocumentID'); |
| 35 | - | |
| 36 | 35 | if (!checkSession()) { |
| 37 | 36 | exit(0); |
| 38 | 37 | } |
| ... | ... | @@ -54,6 +53,20 @@ require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc" |
| 54 | 53 | require_once("addDocumentUI.inc"); |
| 55 | 54 | require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/store.inc"); |
| 56 | 55 | |
| 56 | +$postExpected = KTUtil::arrayGet($_REQUEST, "postExpected"); | |
| 57 | +$postReceived = KTUtil::arrayGet($_REQUEST, "postReceived"); | |
| 58 | +if (!is_null($postExpected) && is_null($postReceived)) { | |
| 59 | + // A post was to be initiated by the client, but none was received. | |
| 60 | + // This means post_max_size was violated. | |
| 61 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 62 | + $oPatternCustom = & new PatternCustom(); | |
| 63 | + $errorMessage = _("You tried to upload a file that is larger than the PHP post_max_size setting."); | |
| 64 | + $oPatternCustom->setHtml(getStatusPage($fFolderID, $errorMessage . "</td><td><a href=\"$default->rootUrl/control.php?action=browse&fFolderID=$fFolderID\"><img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"></a>")); | |
| 65 | + $main->setCentralPayload($oPatternCustom); | |
| 66 | + $main->render(); | |
| 67 | + exit(0); | |
| 68 | +} | |
| 69 | + | |
| 57 | 70 | if (!isset($fFolderID)) { |
| 58 | 71 | //no folder id was set when coming to this page, |
| 59 | 72 | //so display an error message |
| ... | ... | @@ -84,7 +97,7 @@ if (!isset($fStore)) { |
| 84 | 97 | $oPatternCustom = & new PatternCustom(); |
| 85 | 98 | $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentTypeID, $fDependantDocumentID)); |
| 86 | 99 | $main->setCentralPayload($oPatternCustom); |
| 87 | - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID" . | |
| 100 | + $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&postExpected=1" . | |
| 88 | 101 | (isset($fDependantDocumentID) ? "&fDependantDocumentID=$fDependantDocumentID" : "") . |
| 89 | 102 | (isset($fDocumentTypeID) ? "&fDocumentTypeID=$fDocumentTypeID" : "")); |
| 90 | 103 | $main->setFormEncType("multipart/form-data"); |
| ... | ... | @@ -110,7 +123,17 @@ if (!((strlen($_FILES['fFile']['name']) > 0) && $_FILES['fFile']['size'] > 0)) { |
| 110 | 123 | // no uploaded file |
| 111 | 124 | require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); |
| 112 | 125 | $oPatternCustom = & new PatternCustom(); |
| 113 | - $oPatternCustom->setHtml(getStatusPage($fFolderID, _("You did not select a valid document to upload") . "</td><td><a href=\"$default->rootUrl/control.php?action=addDocument&fFolderID=$fFolderID&fDocumentTypeID=$fDocumentTypeID\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"></a>")); | |
| 126 | + $message = _("You did not select a valid document to upload"); | |
| 127 | + | |
| 128 | + $errors = array( | |
| 129 | + 1 => _("The uploaded file is larger than the PHP upload_max_filesize setting"), | |
| 130 | + 2 => _("The uploaded file is larger than the MAX_FILE_SIZE directive that was specified in the HTML form"), | |
| 131 | + 3 => _("The uploaded file was not fully uploaded to KnowledgeTree"), | |
| 132 | + 4 => _("No file was selected to be uploaded to KnowledgeTree"), | |
| 133 | + 6 => _("An internal error occurred receiving the uploaded document"), | |
| 134 | + ); | |
| 135 | + $message = KTUtil::arrayGet($errors, $_FILES['fFile']['error'], $message); | |
| 136 | + $oPatternCustom->setHtml(getStatusPage($fFolderID, $message . "</td><td><a href=\"$default->rootUrl/control.php?action=addDocument&fFolderID=$fFolderID&fDocumentTypeID=$fDocumentTypeID\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"></a>")); | |
| 114 | 137 | $main->setCentralPayload($oPatternCustom); |
| 115 | 138 | $main->render(); |
| 116 | 139 | exit(0); | ... | ... |
presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc
| ... | ... | @@ -178,6 +178,7 @@ function getPage($iFolderID, $iDocumentTypeID, $iDependantDocumentID = null, $sM |
| 178 | 178 | $sToRender .= getMetaDataForm($iFolderID, $iDocumentTypeID); |
| 179 | 179 | $sActionButtons = "<input type=\"image\" src=\"" . KTHtml::getAddButton() . "\" border=\"0\"/>"; |
| 180 | 180 | $sToRender .= "<input type=\"hidden\" name=\"fStore\" value=\"1\">"; |
| 181 | + $sToRender .= "<input type=\"hidden\" name=\"postReceived\" value=\"1\">"; | |
| 181 | 182 | $sActionButtons .= generateControllerLink("addDocument", $sQueryString , "<img src=\"" . KTHtml::getBackButton() . "\" border=\"0\"/>") . |
| 182 | 183 | generateControllerLink("browse", "fFolderID=$iFolderID", "<img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"/>"); |
| 183 | 184 | |
| ... | ... | @@ -192,6 +193,7 @@ function getPage($iFolderID, $iDocumentTypeID, $iDependantDocumentID = null, $sM |
| 192 | 193 | $sToRender .= getDocumentType($iFolderID, $iDocumentTypeID, $iDependantDocumentID); |
| 193 | 194 | $sActionButtons .= generateControllerLink("browse", "fFolderID=$iFolderID", "<img src=\"" . KTHtml::getCancelButton() . "\" border=\"0\"/>"); |
| 194 | 195 | $sActionButtons .= "<input type=\"image\" src=\"" . KTHtml::getNextButton() . "\" border=\"0\"/>"; |
| 196 | + $sToRender .= "<input type=\"hidden\" name=\"postReceived\" value=\"1\">"; | |
| 195 | 197 | |
| 196 | 198 | $sToRender .= "<table border=\"0\" width=\"100%\" >\n"; |
| 197 | 199 | $sToRender .= "<tr><td>$sActionButtons</td></tr>"; | ... | ... |