473,466 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to save page content to a text file

93 New Member
Hi

I have a popup windows that display the database content and I want to have save button that save content to a text file.

Most code I found is saving a text area.

How do I do that?

Thanks
Oct 22 '07 #1
5 3910
pbmods
5,821 Recognized Expert Expert
Heya, NMA.

Create a new PHP script to load and save the database content and link to that file.

You can tell the browser to display the content as text by using this line:
Expand|Select|Wrap|Line Numbers
  1. header('Content-type: text/plain; charset=characterSetGoesHere');
  2.  
The value of charset is generally 'utf-8', but you might have a long string that begins with 'iso' if you develop on a Windows system.

You can also create a force download script.
Oct 22 '07 #2
nma
93 New Member
Hi,

Sorry I'm a bit blurr on the complete code sinde my deadline is only one day left. Please can someone let me know the complete code.

Should I make a hyperlink text(to activate the save link etc/save button) that will point to another php file say save.php that will contain all the headers information of php?

I attached the code that display the database content

[PHP]
<?php
session_start();


if(!isset($_SESSION['user'])) {
header('Location: /Login.html');
die();
}
?>

<!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>
<SCRIPT LANGUAGE="JavaScript">


function varitext(text){
text=document
print(text)
}

</script>




<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>See All My Notes</title>
<link rel="stylesheet" href="moviebrowser2.css" type="text/css" title="Default" media="screen"/>
<style type="text/css">
.style2 {color: #FFFFCC}

</style>
</head>

<span class="style2"></span>
<body bgcolor="#FFFFFF">

<table width="750" border="0">

<?php
include_once('../ez_sql.php');
?>

<tr>
<td width="100" align="left" valign="top" class="movieinfo_headtext">Movie Title </td>
<td width="300" align="left" valign="top" class="movieinfo_headtext">Notes </td>
<td width="100" align="left" valign="top" class="movieinfo_headtext">Date </td>
<td width="150" align="left" valign="top" class="movieinfo_headtext">Event Category </td>
<td width="100" align="center" valign="top" class="movieinfo_headtext">Event No. <br/></td>
</tr>
<?php

$notesDetails = $db->get_results("exec spShow_Movie_And_Events_Notes_By_User " . $_SESSION['user']->userID ." ");


foreach ($notesDetails as $notes)
{
?>
<tr>
<td width="100" align="left" valign="top" class="displayNotesBox1"><?php echo $notes->movieTitle;?></td>
<td width="300" align="left" class="displayNotesBox1" valign="top"><?php echo $notes->noteText;?></td>
<td width="100" align="left" valign="top" class="displayNotesBox1"><?php echo $notes->noteDate;?></td>
<td width="150" align="left" valign="top" class="displayNotesBox1"><?php echo $notes->EventCategory;?></td>
<td width="100" align="center" valign="top" class="displayNotesBox1"><?php echo $notes->eventNo;?><br/></td>
</tr>

<?php
}
?>
<tr>
<td></br></br></br></br></td>
</tr>

<tr>
<td>

<DIV ALIGN="CENTER">
<FORM>
<INPUT NAME="print" TYPE="button" VALUE="Print this Page"
ONCLICK="varitext()">
</FORM>
</DIV>
<!-- <form method="post">
<input name="save" type="submit" value="Save My Notes"></td>
</form> -->
</td>
</tr>
</table>
</body>
</html>



[/PHP]
Oct 23 '07 #3
nma
93 New Member
Hi
How do I change the code below if I want the filename will depend on username and not hardcode like $myFile = "Notes.txt"; below? The filename will be say "username.txt"

Thnask

[PHP]
<?php
session_start();

// Make sure users are logged in.
if(!isset($_SESSION['user'])) {
header('Location: /MB2Login.html');
die();
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Save Notes</title>


</head>
<html>

<?php
include_once('../ez_sql.php');
?>

<body>
<?php
//to create a file
$myFile = "Notes.txt";

$fh = fopen($myFile, 'w') or die("can't open file");[/PHP]
Oct 25 '07 #4
pbmods
5,821 Recognized Expert Expert
Heya, NMA.

Try this:
Expand|Select|Wrap|Line Numbers
  1. $myFile = "{$_SESSION['user']}.txt";
  2.  
Oct 25 '07 #5
nma
93 New Member
thank you very much!!!!
Oct 26 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Aliza Klein | last post by:
I am new to ASP so please pardon me if this is crazy. I have data that I want to allow the user to be able to save in a format that will then enable the user to open the data in Excel. (I have...
2
by: RickL | last post by:
I have an ASP application that uploads a specified file to the server. To retrieve the file, I simply assign the filepath and file to a hyperlink on the page. When you click "Save Target As" for...
4
by: David W. Simmonds | last post by:
Is there a way I can have a button on a ASP.NET form that when clicked will allow the user to save the image to a file on the client side? I know that the user can simply rclick the image and...
7
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a...
0
by: Dune | last post by:
Hi there, I have an aspx page that allows users to enter several parameters using drop downs and text boxes. The users then press a button that produces an extract based on the parameters they...
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
8
by: DanB | last post by:
This is probably soooo simple but I can't seem to get it. I have a text file that I want users to download via a web page. I want the file to be saved to a default folder (or one that they...
12
by: =?Utf-8?B?RnJlZU5FYXN5?= | last post by:
Hello, the scenario: There's an ASPX page which shows some text and has three buttons at the bottom: Save, Print and Close. Print and close is done by javascript. But how can I save the page...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.