Skip to content Skip to sidebar Skip to footer
Reading Time: < 1 minute

This publish is describing the way to export contents as text file/txt file utilizing php.This could be very straightforward to export content material as textual content file.You can download the textual content file too.

$textContent = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.'; // custom contents
 		$txtfile = $_SERVER["DOCUMENT_ROOT"]."/download/export_links.txt";
 		$handle = fopen($txtfile, 'w') or die('Cannot open file:  '.$txtfile); // check the file is readable
 		fwrite($handle, $textContent); // write content
		fclose($handle); // close the text file
	 	$downLink = 'download/download.php?f=export_links.txt'; // text file download hyperlink

download.php file could be very urgent due to that file will enable to force download the textual content file.It’s contents as following.

 
$file = trim($_GET['file-name']); 
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=".$file."");
header("Content-Transfer-Encoding: binary");
header("Content-Type: binary/octet-stream");
readfile($file); 

That’s all.