Current location: Hot Scripts Forums » General Web Coding » HTML/XHTML/XML » how to display text file using php/html


how to display text file using php/html

Reply
  #1 (permalink)  
Old 05-15-09, 09:03 PM
umarmir_123 umarmir_123 is offline
Newbie Coder
 
Join Date: May 2009
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
how to display text file using php/html

hi,
i want to display contents of text file whenever a user clicks on the button. i have written following code but it doesn't work.
<input type="button" name ="compose" value="compose" onclick= <a href="C:\apache\htdocs\IMS\abc.txt" </a><br>
if anybody know plz help me here.
thnx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-16-09, 07:18 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Code:
<button onclick="location.href=abc.txt">Click to see file</button>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-16-09, 08:13 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
There are at least a couple ways you can do this.
And which way you choose depends on whether you just want to display the contents of the file on the current page or whether you want to display the file on a new page.

If you just want to display it on a new page you can do it like wirehopper showed but slightly different:
HTML Code:
<input type="button" name="compose" value="compose" onclick="location.href='IMS/abc.txt'" /><br />
But if you want to display the file on the current page then you will need to use AJAX.

This first example displays the file in a <div>:
HTML Code:
<script>
function display_file(f)
{
 var httpRequest = new XMLHttpRequest();
 httpRequest.open("GET", f, true);
 httpRequest.send(null);
 httpRequest.onreadystatechange = function()
 {
  if(this.readyState == 4 && this.status == 200)
  {
   document.getElementById("div1").innerHTML = this.responseText;
   }
  }
 }
</script>
<input type="button" name="compose" value="compose" onclick="display_file('IMS/abc.txt')" /><br />
<div id="div1"></div>
You could also display the file in a <textarea> so you can edit it:
HTML Code:
<script>
function display_file(f)
{
 var httpRequest = new XMLHttpRequest();
 httpRequest.open("GET", f, true);
 httpRequest.send(null);
 httpRequest.onreadystatechange = function()
 {
  if(this.readyState == 4 && this.status == 200)
  {
   document.getElementById("t1").value = this.responseText;
   }
  }
 }
</script>
<input type="button" name="compose" value="compose" onclick="display_file('IMS/abc.txt')" /><br />
<textarea id="t1"></textarea>
Or you could do the same thing with an anchor element.

For a new page:
HTML Code:
<a href="IMS/abc.txt">compose</a><br />
In a <div> on the current page:
HTML Code:
<script>
function display_file(f)
{
 var httpRequest = new XMLHttpRequest();
 httpRequest.open("GET", f, true);
 httpRequest.send(null);
 httpRequest.onreadystatechange = function()
 {
  if(this.readyState == 4 && this.status == 200)
  {
   document.getElementById("div1").innerHTML = this.responseText;
   }
  }
 }
</script>
<a href="#" onclick="display_file('IMS/abc.txt')">compose</a><br />
<div id="div1"></div>
In a <textarea> on the current page:
HTML Code:
<script>
function display_file(f)
{
 var httpRequest = new XMLHttpRequest();
 httpRequest.open("GET", f, true);
 httpRequest.send(null);
 httpRequest.onreadystatechange = function()
 {
  if(this.readyState == 4 && this.status == 200)
  {
   document.getElementById("t1").value = this.responseText;
   }
  }
 }
</script>
<a href="#" onclick="display_file('IMS/abc.txt')">compose</a><br />
<textarea id="t1"></textarea>
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 05-16-09, 05:49 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
HTML Code:
<head>
<title>.txt file viewer</title>
<style type="text/css">
body
{
width:1024px;
height:768px;
}
</style>
<script type="text/javascript">
function update_right(e)
{
var i=0;l=e.options.length;
for (i=0;i<l;i++)
        if (e.options[i].selected)
        {
                document.getElementById('iFrame').src=e.options[i].innerHTML;
                break;
        }
}
</script>
</head>
<body>
<select onchange="update_right(this)">
<option>file1.txt</option>
<option>file2.txt</option>
<option>file3.txt</option>
<option>file4.txt</option>
</select>
<iframe id="iFrame" src="file1.txt" height="100%" width="100%"></iframe>
</body>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 05-18-09, 01:12 AM
umarmir_123 umarmir_123 is offline
Newbie Coder
 
Join Date: May 2009
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
how to pass php variable from 1 php page to another

hello,
i need to pass php variables from 1 php page to another,so what are the ways to do it
it.if u need further details of my problem plz let me know. thnx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 05-18-09, 07:00 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Use sessions.
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 05-18-09, 12:05 PM
umarmir_123 umarmir_123 is offline
Newbie Coder
 
Join Date: May 2009
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
i tried sessions but i am not able to acess the session variable in another php page.
i can access variable in the page where i register it and intialize it but upon clicking the link present on this page, this variable is not accessable in the linked page.so what to do?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 05-19-09, 08:06 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Quote:
Originally Posted by umarmir_123 View Post
i tried sessions but i am not able to acess the session variable in another php page.
i can access variable in the page where i register it and intialize it but upon clicking the link present on this page, this variable is not accessable in the linked page.so what to do?
You aren't being very specific.

Did you create the linked page?
Is the linked page within your domain?
Do you have access to the linked page so you can edit it?
Does the linked page have a php extention?

You must start the session in every page you want assess to the session variables.

Example:
pageOne.php
PHP Code:

<?php
session_start
();
$_SESSION["test_Variable"] = "Hello World.";
?>
<html>
<head>
<title></title>
</head>
<body>
<a href="pageTwo.php">Display session variable</a>
</body>
</html>
pageTwo.php
PHP Code:

<?php session_start(); ?>
<html>
<head>
<title></title>
</head>
<body>
<?php
echo empty($_SESSION["test_Variable"]) ? "The session variable is not set." $_SESSION["test_Variable"];
?>
</body>
</html>
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form to Text File Justin171985 PHP 14 02-09-11 12:55 PM
MySQL Query problem Wraith PHP 5 03-06-04 06:16 PM
reading numbers from a text file ASHRAF C/C++ 1 02-16-04 05:31 PM
How to write a php script to load a text file into a table automatically? xmxpcom PHP 2 02-12-04 09:37 AM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 08:19 PM


All times are GMT -5. The time now is 01:37 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.