How can PHP be used to check the file size before uploading it via FTP?

Before uploading a file via FTP using PHP, you can check the file size to ensure it does not exceed a certain limit. This can be done by using the `filesize()` function to get the size of the file in bytes and comparing it to the maximum allowed size. If the file size is within the limit, you can proceed with the FTP upload.

// Specify the maximum allowed file size in bytes
$maxFileSize = 1048576; // 1 MB

// Get the file size
$fileSize = filesize($_FILES['file']['tmp_name']);

// Check if the file size is within the limit
if ($fileSize <= $maxFileSize) {
    // Proceed with FTP upload
    // Your FTP upload code here
} else {
    echo "File size exceeds the limit.";
}