mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2025-03-28 22:51:35 +01:00
LSformElement::image: fix error on non-AJAX form when no file is submited
This commit is contained in:
parent
aeea76ab2a
commit
e62ddbdc19
1 changed files with 17 additions and 3 deletions
|
@ -97,12 +97,11 @@ class LSformElement_image extends LSformElement {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_FILES[$this -> name])) {
|
if ($this -> checkIsInPostData()) {
|
||||||
if (isset($_FILES[$this -> name]['tmp_name']) && is_uploaded_file($_FILES[$this -> name]['tmp_name'])) {
|
if (isset($_FILES[$this -> name]['tmp_name']) && is_uploaded_file($_FILES[$this -> name]['tmp_name'])) {
|
||||||
$fp = fopen($_FILES[$this -> name]['tmp_name'], "r");
|
$fp = fopen($_FILES[$this -> name]['tmp_name'], "r");
|
||||||
$buf = fread($fp, filesize($_FILES[$this -> name]['tmp_name']));
|
$return[$this -> name][0] = fread($fp, filesize($_FILES[$this -> name]['tmp_name']));
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
$return[$this -> name][0] = $buf;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self :: log_debug('LSformElement_image('.$this->name.')->getPostData(): uploaded tmp file not found => '.varDump($_FILES[$this -> name]));
|
self :: log_debug('LSformElement_image('.$this->name.')->getPostData(): uploaded tmp file not found => '.varDump($_FILES[$this -> name]));
|
||||||
|
@ -123,6 +122,21 @@ class LSformElement_image extends LSformElement {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if file is present in POST data
|
||||||
|
*
|
||||||
|
* @return boolean True if file is in POST data, false otherwise
|
||||||
|
*/
|
||||||
|
public function checkIsInPostData() {
|
||||||
|
// Check if present in $_FILES
|
||||||
|
if (!isset($_FILES[$this -> name]) || !is_array($_FILES[$this -> name]))
|
||||||
|
return false;
|
||||||
|
// Check if a file is submited
|
||||||
|
if ($_FILES[$this -> name]['error'] == UPLOAD_ERR_NO_FILE)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get file upload error message
|
* Get file upload error message
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue