$file = $_FILES['file']; if (CFile::checkImageFile($file['tmp_name'])) { echo "File is an image"; } else { echo "File is not an image"; }
$file = $_FILES['file']; if (CFile::checkImageFile($file['tmp_name'])) { // Save the file to the server } else { echo "Only image files are allowed"; }In this example, we are using the CFile CheckImageFile method to restrict file uploads to only images. If the file uploaded is not an image, the message "Only image files are allowed" will be displayed. Package library: This example makes use of the Yii PHP framework, which is a package library that provides a set of tools for building web applications.