Home >Backend Development >PHP Tutorial >PHP general detection function set (4)_PHP tutorial
// Function name: CheckExtendName($C_filename,$A_extend)
// Function: Determine the extension of the uploaded file
// Parameters: $C_filename Uploaded file name
// $A_extend required extension
// Return value: Boolean value
// Remarks: None
//-------------------------- -------------------------------------------------- ------
-------
function CheckExtendName($C_filename,$A_extend)
{
if(strlen(trim($C_filename)) < 5)
{
return 0; //Returning 0 means no picture has been uploaded
}
$lastdot = strrpos($C_filename, "."); //Retrieve the last appearing position
$extended = substr($C_filename, $lastdot+1); //Get the extension
for($i=0;$i
if (trim(strtolower($extended)) == trim(strtolower($A_extend[$i]))) //Convert uppercase
to lowercase and detect
{
$flag=1; //Add success flag
$i=count($A_extend); //Stop detection if detected
}
}
if($flag<>1)
{
for($j=0;$j
$alarm .= $A_extend[$j] ." ";
}
AlertExit (Only .$alarm. files can be uploaded! And you are uploading files of type .$extended.);
return -1; //Return -1 to indicate uploading The type of image does not match
}
return 1; //Returning 1 means that the type of image meets the requirements
}
//-------------------------- -------------------------------------------------- ------------------
-------
//---------- -------------------------------------------------- -----------------------
-------
// Function name: CheckImageSize($ImageFileName,$LimitSize)
// Function: Check the size of the uploaded image
// Parameters: $ImageFileName Uploaded image name
// $LimitSize Required size
// Return value: Boolean value
// Remarks :None
//--------------------------------------------- ----------------------------------------
-------
function CheckImageSize($ImageFileName,$LimitSize)
{
$size=GetImageSize($ImageFileName);
if ($size[0]>$LimitSize[0] ││ $size[ 1]>$LimitSize[1])
{
AlertExit(image size is too large);
return false;
}
return true;
}
// -------------------------------------------------- ----------------------------------
-------
//--------------------------------------------- -------------------------------------
------
// Function name: Alert($C_alert,$I_goback=0)
// Function: Illegal operation warning
// Parameter: $C_alert (error message prompted)
// $I_goback (return to That page)
// Return value: String
// Remarks: None
//----------------------- -------------------------------------------------- ----------
-------
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>";
}
}
//------------------ -------------------------------------------------- ---------------
-------
//-------------- -------------------------------------------------- ------------------
-------
//----------------- -------------------------------------------------- ----------------
-------