PHP Safe Upload image method, _php tutorial

Source: Internet
Author: User
Tags php form

How to safely upload images in PHP,


This article describes the way PHP securely uploads images. Share to everyone for your reference. The specific analysis is as follows:

This code is used to upload images, you can detect the image according to the type of image is safe, not a simple detection 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 a accepted image file";} else echo "No image has been uploaded"; echo ";? >

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/970976.html www.bkjia.com true http://www.bkjia.com/PHPjc/970976.html techarticle php Safe Upload image method, this article describes the PHP safe upload image method. Share to everyone for your reference. The specific analysis is as follows: This code is used to upload images, you can ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.