Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 22.x
Latest version:
pecl install openswoole-22.1.2
<?php Swoole\Http\Request->files: array
None
Array
The Swoole\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 Swoole\Http\Request->files
instead.
The Swoole\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(Swoole/Server/Request $request, Swoole/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 Swoole 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 Swoole 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