0

I have a database some short notes in a .txt format file and i have created a php webpage that includes a txt file in html format. Now I have to use "Next" and "Preview" links for that .txt format files.
Can anyone suggest me the php or JavaScript code for that..
I have a suggetion if i name that all short notes files as 1, 2, 3, ... so can i use next and preview by using loop in javascript or php?? Can you suggest me that code?? Please....

4
Contributors
13
Replies
14
Views
7 Years
Discussion Span
Last Post by kirtan_thakkar
Featured Replies
  • Use following script, nothing more to do. Set your text directory path in currdirectory folder. [code] <?php $currdirectory="textfilesfolder";//path or your current directory from where you want to show files. i assume all files are text files if($_REQUEST['txtfile']=="") $txtfile=$currdirectory."/1.txt"; else $txtfile=$currdirectory."/".$_REQUEST['txtfile']; $files = scandir($currdirectory); $nextfile=$files[2]; for ($i=0;$i<count($files);$i++) { $content=$currdirectory."/".$files[$i]; if (is_file($content)) … Read More

  • My fisrt script was better. it shows all files in your directory in file order. you may user a.txt... like that. another version given below based on 1,2,3,4 series, which depends on series of number. if suppose 5.txt is not there then below script will fail. [code] $currdirectory=".";//path or your … Read More

0

I have text File like this
Text File 1: Knowledge is meaningful only if it is reflected in action. The human race has found out the hard way that we are what we do, not just what we think. This is true for kids and adults — for schoolrooms and nations. Text File 2: One thing we have endeavoured to observe most scrupulously, namely, never to depart from the strictest facts and, in dealing with the difficult questions that have arisen during the year, we hope that we have used the utmost moderation possible under the circumstances I have used the code as under in my page:

<?php
$filename="1.txt";
$handle=fopen($filename,"r");

$contents=fread
($handle,filesize($filename));

echo($contents);
?>

Than I have added "Next" And "Previous" Buttons. I have to create a code for which when i click on "Next" Button In the php code the file name get change to "2.text". And on that page on clicking on "Next" button the file name should have to change to "3.txt". As like this in "Previous" buton..
Please Help..

Edited by kirtan_thakkar: n/a

0

Logic:

i) Store the filenames in a Array $fnames=array("1.txt","2.txt","3.txt");
ii) Write the above code in a function with arguments as your filename
iii) on you click on next button call the function by passing the array value

To process the same page again you can use:

<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<input type="button" name="submit" value="Next">
</form>

<?php
if(isset($_POST['submit'])) {
task;
}

Hope you understand the logic.

Edited by rajarajan07: n/a

0

Thanks for the reply.. I have understood.
Sorry but can you tell me how to pass the array..???

1

Use following script, nothing more to do. Set your text directory path in currdirectory folder.

<?php
	$currdirectory="textfilesfolder";//path or your current directory from where you want to show files. i assume all files are text files
	if($_REQUEST['txtfile']=="")
		$txtfile=$currdirectory."/1.txt";
	else
		$txtfile=$currdirectory."/".$_REQUEST['txtfile'];
	
	
	$files = scandir($currdirectory);				
	$nextfile=$files[2];
	for ($i=0;$i<count($files);$i++)
	{
		$content=$currdirectory."/".$files[$i];
	 	if (is_file($content))
	 	{
	 	 	if($_REQUEST['txtfile']==$files[$i])
	 	 	{
				$prevfile=$files[$i-1];
				//$txtfile=$files[$i];
				$nextfile=$files[$i+1];
				break;
			}
		}

	}
	
	$handle=fopen($txtfile,"r");
	$contents=fread($handle,filesize($txtfile));
	echo($contents);
	fclose($handle);

	if($prevfile!="" && $i>=3)
		print "<br><a class='text17' href='{$_SERVER['PHP_SELF']}?txtfile={$prevfile}'>Previous</a>&nbsp;&nbsp;";
	if($nextfile!="")
		print "&nbsp;<a class='text17' href='{$_SERVER['PHP_SELF']}?txtfile={$nextfile}'>Next</a>";
 
         ?>

Edited by urtrivedi: n/a

0

Hey..
Is there any problem in the script..??
Because when I am adding 10 files there is not the "Next" button in 9.txt file..
When I opened typing 10.txt in the address bar there is a next button on 10.txt file. From which I was back to 2.txt..
Please help..

I amgetting this series after pressing the "next" button on 1.txt
1,1,10,2,3,4,5,6,7,8,9

Thanks for Helping..

Edited by kirtan_thakkar: n/a

0

Hey..
Is there any problem in the script..??
Because when I am adding 10 files there is not the "Next" button in 9.txt file..
When I opened typing 10.txt in the address bar there is a next button on 10.txt file. From which I was back to 2.txt..
Please help..

I am getting this series after pressing the "next" button on 1.txt
1,1,10,2,3,4,5,6,7,8,9

Check it out this prob on this link..
http://tiny.cc/bto6o

Thanks for Helping..

0

So can I use a.txt,b.txt,c.txt insted of 1,2,3...???????????

1

My fisrt script was better. it shows all files in your directory in file order. you may user a.txt... like that.

another version given below based on 1,2,3,4 series, which depends on series of number. if suppose 5.txt is not there then below script will fail.

$currdirectory=".";//path or your current directory from where you want to show files. i assume all files are text files
	if($_REQUEST['txtfile']=="")
		$txtfile=$currdirectory."/1".".txt";
	else
		$txtfile=$currdirectory."/".$_REQUEST['txtfile'].".txt";
	

	if(file_exists($currdirectory."/".($_REQUEST['txtfile']-1).".txt"))
		$prevfile=$_REQUEST['txtfile']-1;
	if(file_exists($currdirectory."/".($_REQUEST['txtfile']+1).".txt"))
		$nextfile=$_REQUEST['txtfile']+1;
	

	$handle=fopen($txtfile,"r");

	$contents=fread($handle,filesize($txtfile));
	echo($contents);
	fclose($handle);
	echo "<br>";
	if($prevfile!="" )
		print "<a class='text17' href='{$_SERVER['PHP_SELF']}?txtfile={$prevfile}'>Previous</a>&nbsp;&nbsp;";
	if($nextfile!="")
		print "&nbsp;<a class='text17' href='{$_SERVER['PHP_SELF']}?txtfile={$nextfile}'>Next</a>";

its your choice what to use

Edited by urtrivedi: n/a

0

Thank you....... So Much............

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.