Receiving files using PHP on a server
Before we can upload a file to a server, we need to have something on the server that can receive and process the file. At a minimum, this process writes the file to a specific location on the server, but there's usually a little bit more going on. Usually, the request is checked to make sure something fishy isn't going on (such as a file is too large or of the wrong type). Then, the file is almost always renamed to prevent naming collisions. After this, it's up to you: you could run a virus scan on the file, resize it (if it's an image), upload it to a backend database, send it to another server, and so on.
Note
The snippets in this section are located at snippets/09/ex2-uploading-files
in the code package of this book. When using the interactive snippet playground, select 9: Transferring Files and Example 2.
The File Transfer plugin we've been using so far uses a multipart HTTP POST
request to upload data, which is very useful. It means that we can use...