This article mainly introduces PHP's secure image Upload method, which can detect image types and realize the function of safely determining images, which is of great practical value, for more information about how to upload images securely in PHP, see the following example. Share it with you for your reference. The specific analysis is as follows:
This code is used to upload an image. you can check whether the image is safe based on the image type. it is not a simple extension.
<? Php // upload. phpecho <_ ENDPHP Form Upload_ END; if ($ _ FILES) {$ name = $ _ FILES ['filename'] ['name']; switch ($ _ FILES ['filename'] ['type']) {case 'image/jpeg ': $ ext = 'jpg'; break; case 'image/GIF ': $ ext = 'GIF'; break; case 'image/png ': $ ext = 'PNG'; break; case 'image/tiff ': $ ext = 'tif '; break; default: $ ext = ''; break;} if ($ ext) {$ n =" image. $ ext "; move_uploaded_file ($ _ FILES ['filename'] ['tmp _ name'], $ n); echo" Uploaded image '$ name' as '$ n ':
"; Echo" ";} else echo" '$ name' is not an accepted image file ";} else echo" No image has been uploaded "; echo" ";?>
I hope this article will help you with php programming.