note 124507 added to features.file-upload.errors
| From: | admin at compumatter dot com | Date: | Sat, 14 Dec 2019 19:42:20 +0000 |
| Subject: | note 124507 added to features.file-upload.errors | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-213515@lists.php.net to get a copy of this message | ||
We use this function to handle file uploads.
Since $_FILES allows for more than a single file, this loops through each file and if there's
an error, it is displayed in human readable language to the error log and then returned / exited.
You can adjust that to echo's if preferred:
function file_upload_test($messageBefore="CM FILE UPLOAD MESSAGE"){
global $_FILES;
# a single file limit
$upload_max_size = ini_get('upload_max_filesize');
# the combination of a batch o multiple files
$post_max_size = ini_get('post_max_size');
# array of possible fails which are retuned below in if $key=error section
$phpFileUploadErrors = array(
0 => 'There is no error, the file uploaded with success',
1 => 'Exceeds php.ini upload_max_filesize of '.$upload_max_size.'MB',
2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in
the HTML form',
3 => 'The uploaded file was only partially uploaded',
4 => 'No file was uploaded',
6 => 'Missing a temporary folder',
7 => 'Failed to write file to disk.',
8 => 'A PHP extension stopped the file upload.',
);
error_log("========================================");
error_log("$messageBefore");
error_log("========================================");
foreach ($_FILES['cmmediabrowsedfor'] as $key => $value) {
${$key}=$value;
error_log('$_FILES ['.$key.'] = ['.$value.']');
if(is_array($value)){
foreach ($value as $key2 => $value2) {
error_log(' > $_FILES ['.$key.']['.$key2.'] =
'.$value2);
if($key=='error'){
error_log(' ******* CM Failed Upload:
'.$phpFileUploadErrors[$value2]);
error_log(' Exit / Return in
plugins/cm-alpha/php/images/img-create-tmp.php');
error_log(' ');
exit;
}
}
}
}
if(!file_exists($_FILES["cmmediabrowsedfor"]["tmp_name"][0]) ||
!is_uploaded_file($_FILES["cmmediabrowsedfor"]["tmp_name"][0])) {
error_log("NO FILE GOT UPLOADED ");
} else {
error_log("SUCCESS FILE GOT UPLOADED ");
}
}
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.157.54 (proxied: 96.69.208.120)
----
Manual Page -- http://php.net/manual/en/features.file-upload.errors.php
Edit -- https://master.php.net/note/edit/124507
Del: integrated -- https://master.php.net/note/delete/124507/integrated
Del: useless -- https://master.php.net/note/delete/124507/useless
Del: bad code -- https://master.php.net/note/delete/124507/bad+code
Del: spam -- https://master.php.net/note/delete/124507/spam
Del: non-english -- https://master.php.net/note/delete/124507/non-english
Del: in docs -- https://master.php.net/note/delete/124507/in+docs
Del: other reasons-- https://master.php.net/note/delete/124507
Reject -- https://master.php.net/note/reject/124507
Search -- https://master.php.net/manage/user-notes.php