Do I really need the Content-Type header?
I tried removing the switch statement bit, and it worked.
So what's really the point of the Content-Type header if the browser detect the type based on the extension anyway?
And is there a way to make the random text generation faster?
And how can I set a max limit on the filesize?
<?php
$size = $_GET['size'];
$extension = $_GET['extension'];
$filename = $_GET['filename'] . "." . $extension;
$content = '';
for ($i = 0; $i < $size; $i++) {
$content .= chr(mt_rand(0, 255));
}
switch($extension) {
case "xls":
header("Content-type: application/msexcel");
break;
case "doc":
header("Content-type: application/msword");
break;
case "txt":
header("Content-type: application/notepad");
break;
}
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
print $content;
?>