Php checks the uploaded file type and image size code

Source: Internet
Author: User
There are two examples in this article to check the Upload file type and the size of the uploaded image. I originally wanted to separate the two files, but I thought it would be better to put them together. There are two examples in this article to check the Upload file type and the size of the uploaded image. I originally wanted to separate the two files, but I thought it would be better to put them together.

// Function name: CheckExtendName ($ C_filename, $ A_extend) // used for determining the extension of the uploaded file // parameter number: $ C_filename: the file name to be uploaded // The extension required by $ A_extend // return value: Boolean // backup Note: None // functions CheckExtendName ($ C_filename, $ A_extend) {if (strlen (trim ($ C_filename) <5) {return 0; // return 0 indicating that no image is uploaded} $ lastdot = strrpos ($ C_filename ,". "); // retrieve. last Location $ extended = substr ($ C_filename, $ las Tdot + 1); // Retrieve the extension for ($ I = 0; $ I {if (trim (strtolower ($ extended )) = trim (strtolower ($ A_extend [$ I]) // converts case sensitivity and detects {$ flag = 1; // add the success flag $ I = count ($ A_extend); // if ($ flag <> 1) {for ($ j = 0; $ j {$ alarm. = $ A_extend [$ j]. "";} AlertExit ('only upload '. $ alarm. 'file! And you uploaded '. $ extended. 'type file'); return-1; // return-1 indicates the type of the uploaded image does not match} return 1; // 1 indicates that the image type meets the requirements} // response // Function name: CheckImageSize ($ ImageFileName, $ LimitSize: check the size of the uploaded image. // parameter: $ ImageFileName indicates the size required for the uploaded image. // the returned value is Boolean. // Note: None. // check the function CheckI. MageSize ($ ImageFileName, $ LimitSize) {$ size = GetImageSize ($ ImageFileName ); if ($ size [0]> $ LimitSize [0] │ $ size [1]> $ LimitSize [1]) {AlertExit ('excessively large image size '); return false;} return true;} // returns // Function name: Alert ($ C_alert, $ I _goback = 0) // for use: Illegal Operation warning // parameter number: $ C_alert (error message) // $ I _goback (returned to that page) // return value: string // standby Note: None //------------------------------ Using function Alert ($ C_alert, $ I _goback = 0) {if ($ I _goback <> 0) {echo "" ;}else {echo "" ;}}?>

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.