Safely upload images with PHP

*文
Release: 2023-03-18 13:54:01
Original
1882 people have browsed it

How to upload images safely in PHP? This article mainly introduces the method of uploading pictures safely in PHP, which can detect the picture type and realize the function of safely judging pictures. I hope to be helpful.

The example in this article describes how to safely upload images in PHP. Share it with everyone for your reference. The specific analysis is as follows:

This code is used to upload pictures. It can detect whether the picture is safe according to the picture type. It is not a simple detection of the extension


PHP Form Upload
Select a JPG, GIF, PNG or TIF File:
_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 ""; ?>
Copy after login

Related recommendations:

php security filter function sample code

PHP secure email

PHP security detection code snippet (share)_PHP tutorial

The above is the detailed content of Safely upload images with PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!