Php universal detection function set (4) _ PHP Tutorial

Source: Internet
Author: User
Php universal function set (4 ). Function name: CheckExtendName ($ C_filename, $ A_extend) function: parameter for determining the extension of the file to be uploaded: $ C_filename indicates the name of the file to be uploaded. the name of the extension required by $ A_extend is returned. // Function name: checkExtendName ($ C_filename, $ A_extend)
// Usage: determine the extension of the uploaded file
// Parameter: $ C_filename: name of the uploaded file
// $ A_extend required extension
// Return value: Boolean
// Standby Note: None
// Configure //-----------------------------------------------------------------------------------
-------
Function CheckExtendName ($ C_filename, $ A_extend)
{
If (strlen (trim ($ C_filename) <5)
{
Return 0; // if 0 is returned, the image is not uploaded.
}
$ Lastdot = strrpos ($ C_filename, "."); // retrieves the last position that appears.
$ Extended = substr ($ C_filename, $ lastdot + 1); // Retrieve the extension

For ($ I = 0; $ I {
If (trim (strtolower ($ extended) = trim (strtolower ($ A_extend [$ I]) // Large conversion
Lowercase and detection
{
$ Flag = 1; // add a success flag
$ I = count ($ A_extend); // if it is detected, the detection is stopped.
}
}

If ($ flag <> 1)
{
For ($ j = 0; $ j {
$ Alarm. = $ A_extend [$ j]. "";
}
AlertExit (only. $ alarm. file can be uploaded! And you uploaded a. $ extended. type file );
Return-1; // return-1 indicates the type of the uploaded image does not match
}

Return 1; // return 1 indicates that the image type meets the requirements.
}
// Configure //-----------------------------------------------------------------------------------
-------


// Configure //-----------------------------------------------------------------------------------
-------
// Function name: CheckImageSize ($ ImageFileName, $ LimitSize)
// Usage: check the size of the uploaded image
// Parameter: name of the image uploaded by $ ImageFileName
// The size required by $ LimitSize
// Return value: Boolean
// Standby Note: None
// Configure //-----------------------------------------------------------------------------------
-------
Function CheckImageSize ($ ImageFileName, $ LimitSize)
{
$ Size = GetImageSize ($ ImageFileName );
If ($ size [0]> $ LimitSize [0] │ $ size [1]> $ LimitSize [1])
{
AlertExit (the image size is too large );
Return false;
}
Return true;
}
// Configure //-----------------------------------------------------------------------------------
-------


// Configure //-----------------------------------------------------------------------------------
-------
// Function name: Alert ($ C_alert, $ I _goback = 0)
// Usage: illegal operation warning
// Parameter: $ C_alert (error message)
// $ I _goback (return to that page)
// Return value: string
// Standby Note: None
// Configure //-----------------------------------------------------------------------------------
-------
Function Alert ($ C_alert, $ I _goback = 0)
{
If ($ I _goback <> 0)
{
Echo "script" alert ($ C_alert); history. go ($ I _goback); script ";
}
Else
{
Echo "script" alert ($ C_alert); script ";
}
}
// Configure //-----------------------------------------------------------------------------------
-------


// Configure //-----------------------------------------------------------------------------------
-------
// Configure //-----------------------------------------------------------------------------------
-------

Http://www.bkjia.com/PHPjc/532629.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/532629.htmlTechArticle// function name: CheckExtendName ($ C_filename, $ A_extend) // used for: File Upload extension judgment // parameter number: $ C_filename: the file name to be uploaded // The extension required by $ A_extend // return...

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.