What is the best practice for defining the absolute path in PHP for file transfer functions like ftp_put?

When defining the absolute path in PHP for file transfer functions like ftp_put, it is important to use the correct path format based on the server's operating system. For example, on Unix-based systems, the absolute path should start with "/", while on Windows systems, it should start with the drive letter followed by ":". It is also recommended to use the PHP constant __DIR__ to get the directory of the current script and build the absolute path from there.

// Get the absolute path of the file using __DIR__
$localFile = __DIR__ . '/example.txt';

// Define the FTP server path
$ftpPath = '/remote/path/example.txt';

// Connect to FTP server
$ftp = ftp_connect('ftp.example.com');

// Login to FTP server
ftp_login($ftp, 'username', 'password');

// Upload the file to FTP server
ftp_put($ftp, $ftpPath, $localFile, FTP_BINARY);

// Close FTP connection
ftp_close($ftp);