Example 1 — Get a File Size
Ask the server how big a file is and print it in bytes.
<?php
$ftp = ftp_connect('ftp.example.com');
ftp_login($ftp, 'demo', 'secret');
$bytes = ftp_size($ftp, 'report.pdf');
echo "report.pdf is $bytes bytes", PHP_EOL;
ftp_close($ftp); How It Works
- After logging in, ftp_size() sends the SIZE command for report. pdf.
- The server replies with the number of bytes in the file.
- That number is saved in the $bytes variable.
- echo prints the message with the size inside it.

