mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 14:23:57 -07:00
Improved handling errors while uploading (#1246)
This commit is contained in:
parent
fbc4749ca9
commit
486e5cc7d2
2 changed files with 30 additions and 28 deletions
|
@ -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<br><b>upload_max_filesize</b> 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'] . '<br><br>' . $lang['UPLOAD_ERRORS'][$this->error]);
|
||||
} else {
|
||||
bb_die($lang['UPLOAD_ERROR_COMMON']);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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'] . '<br><br>' . $lang['UPLOAD_ERRORS'][$this->error];
|
||||
} else {
|
||||
$this->errors[] = $lang['UPLOAD_ERROR_COMMON'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue