Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Http\Request->files: array
None
Array
The OpenSwoole\Http\Request->files
class property is an array which contains the information for HTTP POST files that were sent to the server.
All the keys of this array are lowercase. You use this array to interact with uploaded files from the client, it is equivalent to the PHP super global variable $_FILES
but you should use OpenSwoole\Http\Request->files
instead.
The OpenSwoole\Http\Request->files
array is usually used when a client uploads a file from a HTML form for example. This array is formatted to be a 2D array based on the uploaded file name, which you can access details about the uploaded file.
<?php
$server->on('Request', function(OpenSwoole\Server\Request $request, OpenSwoole\Server\Response $response)
{
var_dump($request->files['profile_image']);
});
Output from an uploaded file
name
: The name of the file from the client, for example my_profile_image.jpg
type
: The file MIME type, for example image/jpeg
tmp_name
: The area where the uploaded file is stored before being saved permanently, for example /tmp/swoole.upfile.n3FmFr
, this file is generated by OpenSwoole so you can process the file, this directory can be set in the server configurationerror
: An error code which indicates any upload errors, 0
for successful uploadsize
: The size of the uploaded file in bytesThe maximum file size must not exceed the value set by package_max_length
Do not use the OpenSwoole server to handle large file uploads, instead you will need to perform chunk uploads or file streaming
When the request ends, the $request
object is destroyed and so are any temporary uploaded files