0

I have a form that was working normally until our host updated the PHP version to 7.3.11. Now when you try to submit to the form it gives this error message:

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

I didn't change any of the code. The only thing that changed was the PHP version. As a result, I'm not even sure how to start fixing this.

Here's what's on class.upload.php > line 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');
            }
        }

...and here's what's on lib.upload.php > Line 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();
    }
}

Based on that I'm not sure what to change and I don't want to break what was working before.

All the rest of the website is working normally, including PHP functions like logging in. Thanks in advance for any pointers.

D.W.
  • 11
  • 4
  • 2
    Does this answer your question? [Fatal error: Uncaught ArgumentCountError: Too few arguments to function](https://stackoverflow.com/questions/43521468/fatal-error-uncaught-argumentcounterror-too-few-arguments-to-function). Especially [this answer](https://stackoverflow.com/a/45848493/965834). – Jeto Nov 06 '20 at 21:41
  • Hi @Jeto Thank you. Unfortunately no it does not because my function has the 3 arguments expected. – D.W. Nov 06 '20 at 21:44
  • 1
    No it doesn't? `sl_upload($_FILES['quest']['tmp_name'][$this->id], $path.$savefile)` <- you're passing 2 arguments, the function is expecting 3. – Jeto Nov 06 '20 at 21:46
  • First, let me preface by saying the only thing that's changed is that the PHP version updated. All of this code was working normally before that. By my count this has 3: 1) ['quest'] 2) ['tmp_name'] 3) [$this->id]. Am I missing something? – D.W. Nov 06 '20 at 21:48
  • 1
    `$_FILES['quest']['tmp_name'][$this->id]` is the first argument, `$path.$savefile` is the second argument. The reason it worked before is probably because PHP versions < 7.1 used to generate only a warning when that happened, but since then it's been changed to a Fatal error. See the second link in my first comment. – Jeto Nov 06 '20 at 21:50
  • Ok, I see what you're saying. So based on that and the 2nd answer in your 1st comment, would the solution be to add [$file_ext = null] to class.upload.php > line 331? – D.W. Nov 06 '20 at 21:56
  • Don't take it the wrong way, but some of your comments make me think you're lacking some of the language's basics. But anyway, it's very hard to give you a solution unless we know what the `sl_upload` function needs its 3rd parameter for. Would have to see the whole thing, not just the first line. – Jeto Nov 06 '20 at 22:00
  • No offense taken. I'm very inexperienced with this language and am working to learn. Thank you for helping me. I just updated the question contents with the full sl_upload function. – D.W. Nov 06 '20 at 22:07

1 Answers1

0

Try replacing:

sl_upload($_FILES['quest']['tmp_name'][$this->id], $path.$savefile)

with:

sl_upload($_FILES['quest']['tmp_name'][$this->id], $path.$savefile, null);

Explanation: the sl_upload function is expecting 3 arguments, and you're passing only 2.

Before PHP 7.1, this only triggered a warning, but since then it's generating a Fatal Error instead.

Since it worked fine for you before (although, it must have triggered a Warning, which probably got logged somewhere unless your error_reporting is very lax), passing null as the third argument should produce the same outcome as it used to.

It would, however, be a better idea to figure out what that function argument is supposed to be used for, as it's marked as required (no default value).

Jeto
  • 14,596
  • 2
  • 32
  • 46
  • 1
    Thank you @Jeto. This resolved the issue short term and I'll keep looking into your recommendations. – D.W. Nov 06 '20 at 22:40