How to upload images using PHP?

Well, that's why I saw a lot of discussion about how to protect image upload forms, but no one told me what to do exactly up to 100% so that the malicious code would load through my application.

I am currently thinking of recreating the image, as I have seen that it will be a fairly safe method. Does it have? What other options are there? Also, which extensions are preferred using these methods?

+3
source share
2 answers

I am currently thinking of creating an image, as I have seen that it will be a pretty safe way.

, , : P. , , , .

, Fileinfo (mime_content_type() PHP).

PHP- Mimetype, Fileinfo:

. .


, PHP ... CVE. , - :

, GD , , . , ImagMagick Gmagick ... ImageMagick ( , ), Gmagick .

+2

, , .

   $finfo = new finfo(FILEINFO_MIME_TYPE);
   $fileContents = file_get_contents($_FILES['some_name']['tmp_name']);
   $mimeType = $finfo->buffer($fileContents);
+1
source

All Articles