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();
}