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 "" ;}}?>