This article mainly introduces PHP's secure Image Upload method, which can detect image types and realize the function of safely determining images. It is of great practical value. For more information, see
This article mainly introduces PHP's secure Image Upload method, which can detect image types and realize the function of safely determining images. It is of great practical value. For more information, see
This document describes how to upload images securely in PHP. 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.
,