URGENT: PHP QUERY

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
siamesefishAsked:
Who is Participating?
 
rockiroadsConnect With a Mentor Commented:
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
 
siamesefishAuthor Commented:
Thanks rockiroads, where should i put that part of the code?
0
 
rockiroadsCommented:
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
rockiroadsCommented:
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
 
siamesefishAuthor Commented:
I've tried all that.
Now instead of the the error message displaying.
The page comes out blank. : ( What should i do?
0
 
rockiroadsCommented:
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
 
rockiroadsCommented:
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
 
siamesefishAuthor Commented:
hahaha lemme try! brb
0
 
siamesefishAuthor Commented:
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
 
rockiroadsCommented:
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
 
siamesefishAuthor Commented:
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
 
rockiroadsCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.