CodeIgniter file upload API

by: Artur Dziedziczak

October 13, 2021

I went back to PHP and since I haven’t written in it for a couple of years I thought it’s good to check the state of the CodeIgniter framework

API to save files is something I was not expecting since my blurry memory of PHP has information that file upload was a mess. I though maybe I was the only one who could not get my head around and then I read

When you upload files they can be accessed natively in PHP through the $_FILES superglobal. This array has some major shortcomings when working with multiple files uploaded at once, and has potential security flaws many developers are not aware of.

But no more headache! New API is clear and extremely easy to use

$path = $this->request->getFile('userfile')->store('head_img/', 'user_name.jpg');

I think there is much to learn from the architecture of this framework. What a time to be alive!