SitePoint Sponsor |
|
User Tag List
Results 1 to 11 of 11
Thread: PHP cannot read files at all.
-
Aug 11, 2007, 14:21 #1
- Join Date
- Aug 2007
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP cannot read files at all.
I recently setup a testing server on my windows comp (production is on linux) because I was tiredof uploading and running database modifications when I workedon something.
So I downloaded Apache and PHP and set it up. I had to mess with PHP a little to get it to work, but phpinfo(); went off just fine and I was happy.
Until today. Unsure how PHP's MySQLi handled a DESC statement, I wrote off a short test program that needed to require() a general function php. That was 7 hours ago. It never worked.
I wrote some debug statements - here is the php file
PHP Code:print "Read Opening";
//test php
$myfile = "C:\webroot\chardisp\genfunc.php";
print is_file($myfile);
clearstatcache();
print is_readable($myfile);
clearstatcache();
print "Preparing to require";
require $myfile;
print "...";
$dbconn = connectdb();
print "Am I even running?";
$result = $dbconn->query("DESCRIBE rpchar curr_msve");
print_r($result);
$dbconn->close();
I get this for output
"Read Opening11Preparing to require" and it then fails silently.
Running it in the standalone executable gets the same. The errors.txt file records no error emssages, and it is set to E_STRICT.
Nor does Apache record anything. I tried filegetcontents(); but it too, failed silently. What's going on here?
PHP.ini's include path is ".;" and I'm running Apache 2.2.4/PHP 5.2.3 (PHP as a module, Apache runing under Local Service)Last edited by Tokorona; Aug 11, 2007 at 14:22. Reason: Dummy statement.
-
Aug 11, 2007, 14:36 #2
require is not failing silently. If it failed you would get a fatal error so there is no problem there.
What is the code in the include file?
PHP Code:<?php
header('content-type: text/plain');
print "Bring in a new file\n\n";
require './test.php';
#require './bad_test.php';
print $test;PHP Code:<?php
print "Inside Test file\n\n";
$test = 'Mew';
-
Aug 11, 2007, 14:53 #3
- Join Date
- Aug 2007
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well. Failing Silently may not be the best term. But PHP stops executing at this point.
I've commented out all of the include file before, but here it is:
PHP Code:<?php
print "I am included.";
function writeHTMLHeader()
{
print "\<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \n";
print " http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n";
print "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n";
}
function connectdb()
{
$dbconn = new mysqli($dbserver, $dbuser, $dbpass, $dbname);
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
//connection made. Return the object
print "Connection Made";
return $dbconn;
}
function parseMiltaryAlliance($milall)
{
//added in an extra rank, even though it is unlikely to matter.
switch ($milall){
case 'PTA':
return "PT Academy Forces";
break;
case 'NA':
return "Not Applicable";
break;
case 'EA':
return "Earth Alliance Forces";
break;
case 'EFF':
return "Earth Federation Forces"
break;
case 'REA':
return "Rebel Earth Alliance Forces";
break;
case 'KN':
return "Kafarion Navy Forces";
break;
case 'ZAFT':
return "Zodiac Alliance Forces Treaty";
break;
default:
return "ERROR";
}
return "ERROR";
}
function generateUniqueID($dbobject)
{
//array.
$uni_id = array("0");
//longer function.
$result = $dbobject->query("SELECT madeupid FROM rpchar");
while ($row = $result->fetch_row()){
$uni_id[] = $row[madeupid];
}
$result->close(); //free the now unused result.
//now that we have the listing of previously assigned uniqueid's, let's describe the format.
//Capped at 50 characters.
//Should be 3 numeric, 4 alphabetic, then a 8 character string mixing with numbers and characters. Then three greek letters (5 letter only)
// Total 3+4+8+(assume max)+6*3= 15+18=33. Addding a string of numbers after that. (5) long.
$greekLetter = array("Alpha","Beta","Delta","Theta","Psi","Xi","Nu","Mu","Tau","Omega","Chi",
"Kappa","Lamda","Iota","Gamma","Eta","Zeta");
$customid = rand(100,999);
$customid = $customid. gensafevalue(). gensafevalue() . gensafevalue() . gensafevalue();
//the fun thing. The next bit needs to be a mixture, so basically, use rand to generate a number. If it's not in "safevalue" range, regenerate a one digit
// number.
// To be a "fair" number, i put the minimum at 33. It's 57 units away from 90, so the top is 147.
//loop 8 times.
for ($i = 1; $i <= 8; $i++) {
$number = rand(33,147);
if ($number <= 90)
$customid = $customid . gensafevalue();
else
$customid = $customid . rand(0,9);
}
//now add 3 greek letters
for ($i = 1; $i <= 3; $i++) {
$number = rand(1,count($greekLetter));
$customid = $customid . " ". $greekLetter[$number];
}
//FINALLY. Add in 5 more numbers.
$customid = $customid . rand(10000,99999);
return $customid; //return it
}
//returns an alphabetic character
function gensafevalue()
{
$num = 60; //init at a number that forces the while loop to execute
//created because 59-64 (inclusive) is not safe.
while ($num > 59 && $num < 64)
{
$num = rand(33,90);
}
//return the character
return chr($num);
}
function generatepadding($numchars)
{
for ($i = 0; $i < $numchars; $i++)
print(" ");
}
?>
-
Aug 11, 2007, 15:28 #4
- Join Date
- May 2007
- Location
- Poole, UK
- Posts
- 5,077
- Mentioned
- 103 Post(s)
- Tagged
- 0 Thread(s)
I've found that this way of including files seems to be more reliable:
require_once $_SERVER['DOCUMENT_ROOT'] . '/path/to/file/anincludefile.php
-
Aug 11, 2007, 15:35 #5
- Join Date
- Aug 2007
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for the suggestion but it too doesn't work. (Although, I believe from now on that I will use that format)
-
Aug 11, 2007, 16:05 #6
You have an error in parseMiltaryAlliance function
PHP Code:case 'EFF':
return "Earth Federation Forces"
break;
-
Aug 11, 2007, 16:29 #7
- Join Date
- Aug 2007
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Fixed. Still not working.
-
Aug 11, 2007, 17:37 #8
Does the code I posted a few post above work on your system?
-
Aug 11, 2007, 18:22 #9
- Join Date
- Aug 2007
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yes.
-
Aug 11, 2007, 18:35 #10
- Join Date
- Aug 2007
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Addendum:
Tested it in the subdirectory. STILL works. I guess the problem must be that something in genfunc.php causes it to stop PHP from parsing.
Verified when I unlinked genfunc.php
-
Aug 11, 2007, 18:38 #11
- Join Date
- Aug 2007
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
..relinked it. It's now working fine. Thanks for all your help.
Bookmarks