Jump to content

How Do I Make This Myself


jmc92

Recommended Posts

It is quite easy. I am writing the full code of such an application here:Here is 2 files: 1. index.php , 2. confirmation.php and I used result.txt to store the text dataindex.php

<?phpif ($_REQUEST['submit']){  $psptext = $_REQUEST['psptext'];  $filename = 'result.txt';    $fp = fopen ($filename,'w+');  if (fwrite ($fp,$psptext))  {	header ("Location:confirmation.php?val=1");	fclose ($fp);	exit;  }  else    {	header ("Location:confirmation.php?val=0");	fclose ($fp);	exit;  }}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>PSP Text Page</title></head><body>Type your Text Here:<p><form name="psp" method="post" action="index.php"><textarea name="psptext" rows="5" cols="30"></textarea><input type="submit" name="submit" value="Create Text File" /></form></p></body></html>

confirmation.php

<?php$val = $_GET['val'];switch ($val){  case 1:  $msg1 = "Congrats!! Text File Created.";  break;    case 0:  $msg0 = "Error Creating Text File.";}if ($_REQUEST['submit']){$fullPath = 'result.txt'; if ($fd = fopen ($fullPath,"r")) {	$fsize = filesize($fullPath);	$path_parts = pathinfo($fullPath);	$ext = strtolower($path_parts["extension"]);	switch ($ext) {		case "txt":		header("Content-type: txt"); // add here more headers for diff. extensions		header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download		break;		default;		header("Content-type: application/octet-stream");		header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");	}	header("Content-length: $fsize");	header("Cache-control: private"); //use this to open files directly	while(!feof($fd)) {		$buffer = fread($fd, 101240);		echo $buffer;	}}fclose ($fd);exit;}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Confirmation & Download Page</title></head><body><p>  <?php  if ($msg1)  {	echo $msg1;  ?>  <form name="form1" method="post" action="confirmation.php">  <input type="submit" name="submit" value="Download Text File"/>  </form>  <?php  }  else  {	echo $msg0;  }  ?></p></body></html>

Put a text file called result.txt in the same folder of this application.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...