?
Solved

URGENT: PHP QUERY

Posted on 2006-05-16
12
Medium Priority
?
250 Views
Last Modified: 2010-04-17
I asked a PHP related question and get a great reply the other day from someone here.
(Thanks again : )

I've tested the codes on my own server and it worked perfectly.
Here is the code. (Reads data from text file, info.txt and displays the text on a page)

-------------------------------------------------------
<?php
//
// This is looking for 1 parameter and it supplies the
// name of a file to display on the site.  
//

 $txtfile = $_GET['Id'] . '.txt';
     
if ($txtfile <> "null") {
     $Open = fopen ($txtfile, "r");
     if ($Open) {
          $data = file ($txtfile);
          for ($n = 0; $n < count($data); $n++) {
               $GetLine = explode("\t",$data[$n]);
               print ("$GetLine[0]<br>");
          }

          while ($n++ < 15) {
               print ("<br>");
          }
          fclose ($Open);
     } else {
     print ("Error opening event file.");
     }
}

?>
-------------------------------------------------------

The file is called as such: http://www.beyondresearch.sg/notice_board.php?Id=info

Problem is with this new domain host is that somehow thier PHP engine cannot seem to read the codes and process them properly and I get this error message:

Error opening event file.

So im back to square one again. I have notified this domain host and they tell me to check on the php version requirement and whether will this php script works on a Windows server running php.

Would any kind fellow here know what kind of PHP requirements the server would need and if my code is suitable? I am not really a programmer and have no idea where to find the answer to this but here. Any help would be much appreciated. Thank you all.

EJQ
0
Comment
Question by:siamesefish
  • 7
  • 5
12 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 2000 total points
ID: 16689026
does it matter what version php u have? fopen available from php3 only I think

when u moved hosts, was it a different o/s? windows is non case sensitive, unix/linux is

u set $txtfile, why dont u validate it,

try making call to file_exists

$filename = '/path/to/foo.txt';
if (file_exists($filename)) {
   echo "The file $filename exists";
} else {
   echo "The file $filename does not exist";
}


if it dont exist, u know why then

another check to make possibly is if it is readable


if (is_readable($filename)) {
   echo 'The file is readable';
} else {
   echo 'The file is not readable';
}


0
 

Author Comment

by:siamesefish
ID: 16689101
Thanks rockiroads, where should i put that part of the code?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16689140
u can put it after you check for null and before u do fopen

if ($txtfile <> "null") {
     if file_exists($txtfile)) {
         $Open = fopen ($txtfile, "r");
         if ($Open) {
              $data = file ($txtfile);
              for ($n = 0; $n < count($data); $n++) {
                   $GetLine = explode("\t",$data[$n]);
                   Print ("$GetLine[0]<br>");
              }
   
              while ($n++ < 15) {
                   Print ("<br>");
              }
              fclose ($Open);
         } else {
            Print ("Error opening event file.");
         }
    } else {
        Print ("File not found");
    }
}



suggest u print the name of the txtfile in your error messages
I think this will work

print ("File $txtfile not found");


0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 65

Expert Comment

by:rockiroads
ID: 16689147
is_readable returns TRUE if the file or directory specified by filename exists and is readable.
file_exists returns TRUE if the file or directory specified by filename exists; FALSE otherwise

so I guess is_readable is also a valid option
try both (change file_exists to is_readable), see what happens
0
 

Author Comment

by:siamesefish
ID: 16689315
I've tried all that.
Now instead of the the error message displaying.
The page comes out blank. : ( What should i do?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16689458
does the textfile actuall contain anything? add some diagnostics

e.g.

if ($Open) {
    Print "HELLO - START READING FILE<br>");
              $data = file ($txtfile);
              for ($n = 0; $n < count($data); $n++) {
                   $GetLine = explode("\t",$data[$n]);
                   Print ("READLINE HERE -- $GetLine[0]<br>");
              }
   
              while ($n++ < 15) {
                   Print ("<br>");
              }
    Print "BYE - DONE READING FILE<br>");
              fclose ($Open);
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16689465
oops type in print statement

did u spot it?

if ($Open) {
              Print ("HELLO - START READING FILE<br>");
              $data = file ($txtfile);
              for ($n = 0; $n < count($data); $n++) {
                   $GetLine = explode("\t",$data[$n]);
                   Print ("READLINE HERE -- $GetLine[0]<br>");
              }
   
              while ($n++ < 15) {
                   Print ("<br>");
              }
              Print ("BYE - DONE READING FILE<br>");
              fclose ($Open);


missing open bracket in print statement doh!
0
 

Author Comment

by:siamesefish
ID: 16689515
hahaha lemme try! brb
0
 

Author Comment

by:siamesefish
ID: 16689600
the text file contains quiet a bit off stuff
ive tried all options but it just wont display.
i must be some server problem.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16689700
if u not getting anything at all, I wonder if there is a problem with the PHP?

At least before u was getting a page to appear with error message
You can prove if this is the case, if u revert back to original code that u had working

If that is the case then do you have any tools which compiles PHP? It will help identify any possible errors with the new code

0
 

Author Comment

by:siamesefish
ID: 16689767
I will contact the host. See what their input on the case is.
If i dont get a solution in 2 days or so I'll give you the full 500 points.
Either way you have been great. Superb. Thanks rockiroads.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16689830
no probs. I would like u to revert back to what u had though, so at least the page is coming up

perhaps is_readable or file_exists is not supported, hence the use of the compiler
You would have to compile on the host, dont know if that would be possible

Its more important to get u going. Have u thought of posting a quick 20ptr question on the PHP section? Create a question with a link to this question. Hopefully someone may be able to offer more help.

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question