What are the potential syntax errors in the provided PHP code for downloading a file?
The potential syntax errors in the provided PHP code for downloading a file include missing semicolons at the end of lines, incorrect variable names, and missing closing PHP tags. To solve these issues, ensure that all lines end with a semicolon, use correct variable names, and close the PHP tags properly.
<?php
$file = 'example.txt';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
} else {
echo 'File not found.';
}
?>