Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Dispay text files
Index -> Programming, PHP -> PHP Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
da_foz




PostPosted: Fri Oct 01, 2004 7:48 pm   Post subject: Dispay text files

Ok, here is what I want to do.

I have a directory with a bunch of *.txt files in it. What I want is to generate a list of all the file names, and places them on a page. The list will be links, so that when you click on one of them, the *.txt file will be displayed.

Now the part I am having trouble with. What I want is for the *.txt file to be displayed on the same page as the the list of files, but underneath. (ie, like this http://www.redclaw.ca/funnypics.php ).

I got it working for the pics page, but I can't get it working for the 'text jokes'.

Here is the code I am using for the pics page:
code:
<?php



$directory_name = "funPics";
$dh = dir($directory_name);
$i = 0;

$entry = $dh->read();
$entry = $dh->read();

while ($entry = $dh->read()) {


        if ($i==0){

                echo "<tr>";

        }

        echo "<td>";
        echo "<a href = \"http://www.redclaw.ca/funnypics.php?var=$entry\">$entry</a>";


        echo "</td>";
        echo "\n\n";

        $i++;


       
        if ($i == 3){
                $i=0;
                echo "</tr>";
        }

}

if ($i != 0){

        echo "</tr>";

}




?>

<!-- HTML formatting -->

<?php

if ($var != null){


        echo "<img src=\"/funPics/$var\" border=\"0\" alt=\"$var\" />";


}


?>


The problem I'm having modifying this code is that I think I will have to read in the *.txt line by line and then output it, and I just can't get it to work. I've spent much time on the PHP website working on this. Any help would be great.

Thanks.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Fri Oct 01, 2004 8:02 pm   Post subject: (No subject)

What about using include() to insert the text of the document?

code:
<pre><?php include($_GET["var"]); ?></pre>
da_foz




PostPosted: Fri Oct 01, 2004 8:11 pm   Post subject: (No subject)

Ok, I tried that here:
http://www.redclaw.ca/textjokes.php

Try clicking on one of the options and see so that you can see the error.

code:

<?php

if ($var != null){

        include($_GET[ "/funPics/$var" ]);
?>
wtd




PostPosted: Fri Oct 01, 2004 8:18 pm   Post subject: (No subject)

Try using the full path to that directory.
rdrake




PostPosted: Fri Oct 01, 2004 8:24 pm   Post subject: (No subject)

Does
code:
<?php

if ($var != null){

   include("/funPics/".$_GET['$var']);
?>
work?
da_foz




PostPosted: Fri Oct 01, 2004 8:26 pm   Post subject: (No subject)

cartoon_shark wrote:
Does
code:
<?php

if ($var != null){

   include("/funPics/".$_GET['$var']);
?>
work?


That generate this error:
Warning: main(): Unable to access /jokes/ in /home/virtual/site118/fst/var/www/html/textjokes.php on line 134

Warning: main(/jokes/): failed to open stream: No such file or directory in /home/virtual/site118/fst/var/www/html/textjokes.php on line 134

Warning: main(): Failed opening '/jokes/' for inclusion (include_path='.:/php/includes:/usr/share/php:/usr/share/pear') in /home/virtual/site118/fst/var/www/html/textjokes.php on line 134


Oh, and I changed the dir 'funPics' to 'jokes' which is what it should be.
da_foz




PostPosted: Fri Oct 01, 2004 8:27 pm   Post subject: (No subject)

I know I have access to the dir as if I try going to it directly I get it.

http://www.redclaw.ca/jokes/City_Boy.txt
da_foz




PostPosted: Fri Oct 01, 2004 8:28 pm   Post subject: (No subject)

wtd wrote:
Try using the full path to that directory.


Did not seem to change anything.
Sponsor
Sponsor
Sponsor
sponsor
Blade




PostPosted: Sat Oct 02, 2004 3:07 pm   Post subject: (No subject)

okay. there are two ways i'd do this: include the file, or use an iframe.
including i dont like because when you include the text file, it usually doesnt show the new lines where they're supposed to be. using an iframe does that, and it lets you scroll down. i made 2 test pages and you can check them out here.

include:
http://uifgames.8-bit.ca/scripts/txtindex.php
code:

<?

  if ($handle = opendir('txt')) {

    while (false !== ($file = readdir($handle))) {
      if(($file != ".") && ($file != "..")){ 
        echo "<a href=\"txtindex.php?pg=$file\">$file</a><br>";
      }
    }


    closedir($handle);
  }

  if(isset($_GET['pg'])){
    include("txt/" . $_GET['pg']);
  }

?>



iframe:
http://uifgames.8-bit.ca/scripts/txtindex.php
code:
<head>
  <script language="JavaScript">
  <!--
    function changeframe(file){
      document.getElementById('textframe').src = file;
    }
   -->
  </script>
</head>
<?

  if ($handle = opendir('txt')) {

    while (false !== ($file = readdir($handle))) {
      if(($file != ".") && ($file != "..")){ 
        echo "<a onClick=\"changeframe('txt/$file')\" href=\"#\">$file</a><br>";
      }
    }


    closedir($handle);
  }

  echo "<iframe id=\"textframe\" name=\"textframe\"></iframe>";

?>


go into http://uifgames.8-bit.ca/scripts to see the files and directory

as for your including problem.. the directory you are pointing to doesnt exist... so yer obviously gonna have to fix your paths
da_foz




PostPosted: Sat Oct 02, 2004 3:10 pm   Post subject: (No subject)

Ok, I used that exect code only making a change for my directory name. Please go here to see the error:
http://www.redclaw.ca/textjokes.php?pg=City_Boy.txt

I'm thinking I will contact my host as this is really pissing me off. I know the file is there, it was found to generate the list! ARG!

Thanks for all the help people. If you can thing of what may be causing this error please let me know.
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: