更新到 PHP 版本 7.3.11 后出现表单上传错误
Form upload errors after updating to PHP version 7.3.11
在我们的主机将 PHP 版本更新到 7.3.11 之前,我有一个正常工作的表单。现在,当您尝试提交表单时,它会给出此错误消息:
Fatal error: Uncaught ArgumentCountError: Too few arguments to
function sl_upload(), 2 passed in
/nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/modules/question/class.upload.php
on line 331 and exactly 3 expected in
/nfs/c07/h03/mnt/113634/domains/myurl.com/html/lib/lib.upload.php:74
Stack trace: #0
/nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/modules/question/class.upload.php(331):
sl_upload('/var/tmp/phpU0P...', '/appLms/test/2_...') #1
/nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/lib/lib.test.php(1106):
Upload_Question->storeAnswer(Object(Track_Test), Array, '1') #2
/nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/modules/test/do.test.php(1208):
PlayTestManagement->storePage('1', '1') #3
/nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/modules/test/do.test.php(592):
showResult(Object(Learning_Test), 29) #4
/nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/class.module/learning.test.php(309):
in /nfs/c07/h03/mnt/113634/domains/myurl.com/html/lib/lib.upload.php
on line 74
我没有更改任何代码。唯一改变的是 PHP 版本。因此,我什至不确定如何开始解决这个问题。
这是 class.upload.php > 第 331 行
上的内容
sl_open_fileoperations();
if(!sl_upload($_FILES['quest']['tmp_name'][$this->id], $path.$savefile)) {
$savefile = Lang::t('_QUEST_ERR_IN_UPLOAD');
}
sl_close_fileoperations();
} else {
$savefile = Lang::t('_QUEST_ERR_IN_UPLOAD');
}
}
...这是 lib.upload.php > 第 74 行
上的内容
function sl_upload( $srcFile, $dstFile, $file_ext) {
$uploadType = Get::cfg('uploadType', null);
// check if the mime type is allowed by the whitelist
// if the whitelist is empty all types are accepted
require_once(_lib_.'/lib.mimetype.php');
$upload_whitelist =Get::sett('file_upload_whitelist', 'rar,exe,zip,jpg,gif,png,txt,csv,rtf,xml,doc,docx,xls,xlsx,ppt,pptx,odt,ods,odp,pdf,xps,mp4,mp3,flv,swf,mov,wav,ogg,flac,wma,wmv,jpeg');
$upload_whitelist_arr =explode(',', trim($upload_whitelist, ','));
if (!empty($upload_whitelist_arr)) {
$valid_ext = false;
$ext=strtolower(substr(strrchr($dstFile, "."), 1));
if($ext!=""){
$file_ext =strtolower(substr(strrchr($dstFile, "."), 1));
}
foreach ($upload_whitelist_arr as $k=>$v) { // remove extra spaces and set lower case
$ext =trim(strtolower($v));
$mt =mimetype($ext);
if ($mt) { $mimetype_arr[]=$mt; }
getOtherMime($ext, $mimetype_arr);
if ($ext == $file_ext) {
$valid_ext =true;
}
}
$mimetype_arr = array_unique($mimetype_arr);
if ( class_exists('finfo') && method_exists('finfo', 'file')) {
$finfo =new finfo(FILEINFO_MIME_TYPE);
$file_mime_type =$finfo->file($srcFile);
}
else {
$file_mime_type =mime_content_type($srcFile);
}
if (!$valid_ext || !in_array($file_mime_type, $mimetype_arr)) {
return false;
}
}
$dstFile =stripslashes($dstFile);
if( $uploadType == "ftp" ) {
return sl_upload_ftp( $srcFile, $dstFile );
} elseif( $uploadType == "cgi" ) {
return sl_upload_cgi( $srcFile, $dstFile );
} elseif( $uploadType == "fs" || $uploadType == null ) {
return sl_upload_fs( $srcFile, $dstFile );
} else {
$event = new \appCore\Events\Core\FileSystem\UploadEvent($srcFile, $dstFile);
\appCore\Events\DispatcherManager::dispatch(\appCore\Events\Core\FileSystem\UploadEvent::EVENT_NAME, $event);
unlink($srcFile);
return $event->getResult();
}
}
基于此,我不确定要更改什么,我不想破坏之前的工作。
网站的其他所有功能都正常运行,包括 PHP 功能,例如登录。在此先感谢您的指点。
尝试替换:
sl_upload($_FILES['quest']['tmp_name'][$this->id], $path.$savefile)
与:
sl_upload($_FILES['quest']['tmp_name'][$this->id], $path.$savefile, null);
解释:sl_upload
函数需要 3 个参数,而您只传递了 2 个。
Before PHP 7.1, this only triggered a warning, but since then it's generating a Fatal Error instead.
因为它之前对你工作得很好(虽然,它一定触发了一个警告,除非你的 error_reporting
非常松懈,否则它可能被记录在某个地方),传递 null
作为第三个参数应该产生与以前相同的结果。
然而,弄清楚该函数参数应该用于什么是更好的主意,因为它被标记为必需(无默认值)。
在我们的主机将 PHP 版本更新到 7.3.11 之前,我有一个正常工作的表单。现在,当您尝试提交表单时,它会给出此错误消息:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function sl_upload(), 2 passed in /nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/modules/question/class.upload.php on line 331 and exactly 3 expected in /nfs/c07/h03/mnt/113634/domains/myurl.com/html/lib/lib.upload.php:74 Stack trace: #0 /nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/modules/question/class.upload.php(331): sl_upload('/var/tmp/phpU0P...', '/appLms/test/2_...') #1 /nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/lib/lib.test.php(1106): Upload_Question->storeAnswer(Object(Track_Test), Array, '1') #2 /nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/modules/test/do.test.php(1208): PlayTestManagement->storePage('1', '1') #3 /nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/modules/test/do.test.php(592): showResult(Object(Learning_Test), 29) #4 /nfs/c07/h03/mnt/113634/domains/myurl.com/html/appLms/class.module/learning.test.php(309): in /nfs/c07/h03/mnt/113634/domains/myurl.com/html/lib/lib.upload.php on line 74
我没有更改任何代码。唯一改变的是 PHP 版本。因此,我什至不确定如何开始解决这个问题。
这是 class.upload.php > 第 331 行
上的内容sl_open_fileoperations();
if(!sl_upload($_FILES['quest']['tmp_name'][$this->id], $path.$savefile)) {
$savefile = Lang::t('_QUEST_ERR_IN_UPLOAD');
}
sl_close_fileoperations();
} else {
$savefile = Lang::t('_QUEST_ERR_IN_UPLOAD');
}
}
...这是 lib.upload.php > 第 74 行
上的内容function sl_upload( $srcFile, $dstFile, $file_ext) {
$uploadType = Get::cfg('uploadType', null);
// check if the mime type is allowed by the whitelist
// if the whitelist is empty all types are accepted
require_once(_lib_.'/lib.mimetype.php');
$upload_whitelist =Get::sett('file_upload_whitelist', 'rar,exe,zip,jpg,gif,png,txt,csv,rtf,xml,doc,docx,xls,xlsx,ppt,pptx,odt,ods,odp,pdf,xps,mp4,mp3,flv,swf,mov,wav,ogg,flac,wma,wmv,jpeg');
$upload_whitelist_arr =explode(',', trim($upload_whitelist, ','));
if (!empty($upload_whitelist_arr)) {
$valid_ext = false;
$ext=strtolower(substr(strrchr($dstFile, "."), 1));
if($ext!=""){
$file_ext =strtolower(substr(strrchr($dstFile, "."), 1));
}
foreach ($upload_whitelist_arr as $k=>$v) { // remove extra spaces and set lower case
$ext =trim(strtolower($v));
$mt =mimetype($ext);
if ($mt) { $mimetype_arr[]=$mt; }
getOtherMime($ext, $mimetype_arr);
if ($ext == $file_ext) {
$valid_ext =true;
}
}
$mimetype_arr = array_unique($mimetype_arr);
if ( class_exists('finfo') && method_exists('finfo', 'file')) {
$finfo =new finfo(FILEINFO_MIME_TYPE);
$file_mime_type =$finfo->file($srcFile);
}
else {
$file_mime_type =mime_content_type($srcFile);
}
if (!$valid_ext || !in_array($file_mime_type, $mimetype_arr)) {
return false;
}
}
$dstFile =stripslashes($dstFile);
if( $uploadType == "ftp" ) {
return sl_upload_ftp( $srcFile, $dstFile );
} elseif( $uploadType == "cgi" ) {
return sl_upload_cgi( $srcFile, $dstFile );
} elseif( $uploadType == "fs" || $uploadType == null ) {
return sl_upload_fs( $srcFile, $dstFile );
} else {
$event = new \appCore\Events\Core\FileSystem\UploadEvent($srcFile, $dstFile);
\appCore\Events\DispatcherManager::dispatch(\appCore\Events\Core\FileSystem\UploadEvent::EVENT_NAME, $event);
unlink($srcFile);
return $event->getResult();
}
}
基于此,我不确定要更改什么,我不想破坏之前的工作。
网站的其他所有功能都正常运行,包括 PHP 功能,例如登录。在此先感谢您的指点。
尝试替换:
sl_upload($_FILES['quest']['tmp_name'][$this->id], $path.$savefile)
与:
sl_upload($_FILES['quest']['tmp_name'][$this->id], $path.$savefile, null);
解释:sl_upload
函数需要 3 个参数,而您只传递了 2 个。
Before PHP 7.1, this only triggered a warning, but since then it's generating a Fatal Error instead.
因为它之前对你工作得很好(虽然,它一定触发了一个警告,除非你的 error_reporting
非常松懈,否则它可能被记录在某个地方),传递 null
作为第三个参数应该产生与以前相同的结果。
然而,弄清楚该函数参数应该用于什么是更好的主意,因为它被标记为必需(无默认值)。