If you think getimagesize()
is a bit too slow (because all uploads are done in super highspeed as we know ;) ) you can try the fileinfo
library as well. It inspects at least some bytes within the file. It's pretty fast, I use it every day for hundreds of files in an app that should run speedy and it does.
However, what you don't verify you don't know. So probably first checking extension, ensure a safe filename and a safe store and that they are properly send out to the client.
Before letting any image library touch it (and this should include those on the computers of your site's users), for security reasons the file should be scanned by a virus scanner. That's much more slow compared to getimagesize()
, others suggest to take a look into the file for any occurance of <?php
as well to prevent uploading as payload. Naturally this includes checking for phar
files if inclusion is not prevented via the PHP installations security settings (e.g. by suhosin)
Next to on-demand virus scanning, stored files should be checked from time to time again and again because of formerly unknown exploits.
So part of this is always a background job. But even the on demand real-time checks often do not take that much time unless your application does uploads all the time. You might want to introduce some upload-queue, so the upload is already done but the file get's available to the uploader after the necessary tasks have been run.