Tuesday, June 21, 2011

Create a file & provide download option for that file

$myFile = "path_to_dir/test.(EXTENSION)EG jpg,js";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Contents to display";
fwrite($fh, $stringData);
fclose($fh);
if (file_exists($myFile)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($myFile));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($myFile));
ob_clean();
flush();
readfile($myFile);
exit;
}

No comments:

Post a Comment