Protect file upload (size and filetypes limits)


#1

I have REST API written in PHP and base on Slim Framework.

use Slim\Http\UploadedFile;
$uploadedFiles = $request->getUploadedFiles();
$uploadedFile = $uploadedFiles['myFileName'];

How should i protect file uploading script? I want not only to set limits to file size but also protect my web server from uploading anything except images (jpg, png). What are the best practices for file uploading scripts in Slim?


#2

There isn’t anything unique to Slim I can think of-- you would follow the same security guidelines as you would for any other web application.