// Create a CFile object $file = CUploadedFile::getInstanceByName('file'); // Check if file is valid if ($file && $file->getError() == UPLOAD_ERR_OK) { // Move the uploaded file to the desired location $file->saveAs('/path/to/directory/' . $file->getName()); }
// Create a CFile object for the file to be deleted $file = new CFile('/path/to/directory/file.txt'); // Delete the file $file->delete();This example shows how to delete a file using the CFile class. In this case, a new CFile object is created for the file to be deleted. The `delete()` method is then called to remove the file from the server. Overall, the CFile class provides a simple and convenient way to manage files in applications built using the Yii PHP framework.