diff --git a/src/Legacy/Attach.php b/src/Legacy/Attach.php
index 8b4c275be..c0862d046 100644
--- a/src/Legacy/Attach.php
+++ b/src/Legacy/Attach.php
@@ -19,6 +19,14 @@ class Attach
public $attach_filename = '';
public $filename = '';
public $type = '';
+
+ /**
+ * Upload status code
+ *
+ * @var int
+ */
+ public int $error = UPLOAD_ERR_OK;
+
public $extension = '';
public $file_comment = '';
public $num_attachments = 0; // number of attachments in message
@@ -733,30 +741,14 @@ class Attach
$r_file = trim(basename($this->filename));
$file = $_FILES['fileupload']['tmp_name'];
$this->type = $_FILES['fileupload']['type'];
+ $this->error = $_FILES['fileupload']['error'];
- if (isset($_FILES['fileupload']['error'])) {
- switch ($_FILES['fileupload']['error']) {
- case UPLOAD_ERR_NO_FILE:
- bb_die('No file content sent');
- break;
- case UPLOAD_ERR_INI_SIZE:
- bb_die('php.ini
upload_max_filesize setting: ' . ini_get('upload_max_filesize'));
- break;
- case UPLOAD_ERR_FORM_SIZE:
- bb_die('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form');
- break;
- case UPLOAD_ERR_CANT_WRITE:
- bb_die('Failed to write file to disk, check permissions');
- break;
- case UPLOAD_ERR_PARTIAL:
- bb_die('The uploaded file was only partially uploaded');
- break;
- case UPLOAD_ERR_EXTENSION:
- bb_die('File upload stopped by extension');
- break;
- case UPLOAD_ERR_NO_TMP_DIR:
- bb_die('Missing a temporary folder');
- break;
+ // Handling errors while uploading
+ if (isset($this->error) && ($this->error !== UPLOAD_ERR_OK)) {
+ if (isset($lang['UPLOAD_ERRORS'][$this->error])) {
+ bb_die($lang['UPLOAD_ERROR_COMMON'] . '
' . $lang['UPLOAD_ERRORS'][$this->error]);
+ } else {
+ bb_die($lang['UPLOAD_ERROR_COMMON']);
}
}
diff --git a/src/Legacy/Common/Upload.php b/src/Legacy/Common/Upload.php
index 589ca247e..8e5129248 100644
--- a/src/Legacy/Common/Upload.php
+++ b/src/Legacy/Common/Upload.php
@@ -74,6 +74,13 @@ class Upload
*/
public array $errors = [];
+ /**
+ * Upload status code
+ *
+ * @var int
+ */
+ public int $error = UPLOAD_ERR_OK;
+
/**
* Image types array
*
@@ -102,6 +109,7 @@ class Upload
$this->cfg = array_merge($this->cfg, $cfg);
$this->file = $post_params;
+ $this->error = $this->file['error'];
// Check upload allowed
if (!$this->cfg['up_allowed']) {
@@ -109,11 +117,13 @@ class Upload
return false;
}
- // upload errors from $_FILES
- if ($this->file['error']) {
- $msg = $lang['UPLOAD_ERROR_COMMON'];
- $msg .= ($err_desc =& $lang['UPLOAD_ERRORS'][$this->file['error']]) ? " ($err_desc)" : '';
- $this->errors[] = $msg;
+ // Handling errors while uploading
+ if (isset($this->error) && ($this->error !== UPLOAD_ERR_OK)) {
+ if (isset($lang['UPLOAD_ERRORS'][$this->error])) {
+ $this->errors[] = $lang['UPLOAD_ERROR_COMMON'] . '
' . $lang['UPLOAD_ERRORS'][$this->error];
+ } else {
+ $this->errors[] = $lang['UPLOAD_ERROR_COMMON'];
+ }
return false;
}