0
votes

I am developing a task that consists of uploading files, in this context I identified that in some occasions the call to $files = $application->input-> files->get('files', [], 'ARRAY'); returns an empty array, while $_FILES superglobal contains the the file information.

I show the contents of the variables in JSON format

$_FILES

{
    "files": {
        "name": ["test.zip"],
        "type": ["application/zip"],
        "tmp_name": ["/tmp/phpwiA9ch"],
        "error": [0],
        "size": [2993308]
    }
}

$files

[]

I have not been able to identify the reason, I originally identified it when trying to upload a 32MB pdf file, I thought it was a file size issue, but then I identified that it happens with a 3MB zip file, I mention here that I have managed to upload other zip files

I share the media settings

Legal Extensions (File Types): zip, bmp, csv, doc, gif, ico, jpg, jpeg, odg, odp, ods, odt, pdf, png, ppt, txt, xcf, xls, ZIP, BMP, CSV, DOC , GIF, ICO, JPG, JPEG, ODG, ODP, ODS, ODT, PDF, PNG, PPT, TXT, XCF, XLS

Maximum Size (in MB): 100MB

Legal MIME Types: image / jpeg, image / gif, image / png, image / bmp, application / msword, application / excel, application / pdf, application / powerpoint, text / plain, application / x-zip

The solution I think would be to make a call to $_FILES if the content of $files is empty. But I'm interested in knowing the reason for this error

Here the code I am trying

public function uploadAttachments()
{
    $application = JFactory::getApplication();

    $files = $application->input->files->get('files', [], 'ARRAY'); // Here some times is empty

    $helper = new Helper();

    $response = $helper->uploadAttachments($files);

    header('content-type: application/json; charset=utf-8');
    echo json_encode($response);
    $application->close();
}
1

1 Answers

1
votes

The reason for obtaining an empty array when it is called $application->input->files-> get('files', [], 'ARRAY'); is because in the get method of the JInputFiles class it is verified if the file is safe, the verification is done in the static method isSafeFile, after trying a series of verifications if some condition not passes then false will return, in consecuense the method get will return the default value in my case an empty array.

In the case of the file in which I was testing it is because it identifies the extension pl that is noted as: 'These are suspicious text files which may have an executable'

JInputFile class