...

View Full Version : Certain file names won't 'include'



Gremlyn1
01-13-2010, 08:30 PM
I am having a VERY strange problem! I have a new site I am working on and have a very basic index.php:


<?php
include_once 'libs/config.inc.php';
function __autoload($className){
require_once 'libs/classes/' . $className . '.class.php';
}
$conn = new mysql;
if ($conn->conn() !== TRUE) {
die("Database connection could not be made");
}
$output = new tables;
$output->table_id = "govt";
$output->table_class = "display";
$table = $output->output_all('government');

include_once 'libs/layout/header.inc.php';
echo $table;
include_once 'libs/layout/footer.inc.php';
?>


This page will not properly include the classes or the header/footer files. If I remove the attempt at including anything but the config.inc.php, I can properly display my constants from that file, so I know that is working. I can also hard code the classes into the index.php file and they work as expect OR if I change the file names to remove the .inc and .class (with exception of the appropriately functioning config.inc.php) then the page also works. I can't for the life of my figure this one out. I have tried just including the header/foot files without the class code and that does work and vice versa.

phpMyAdmin is installed on the server, so I know that this naming convention is working there. What on earth could possibly be going on?

EDIT: Also forgot to mention that is I use 'include_once' instead of 'require_once' for the class autoloader, I get an error message saying the class can't be found on the line tat I try to instantiate it, whereas with require_once I get a blank screen.

JAY6390
01-13-2010, 08:35 PM
It sounds like the paths are incorrect. Do you have error reporting on?
at the top of your file put

error_reporting(E_ALL);
and see if you get any errors for it

masterofollies
01-13-2010, 08:43 PM
Maybe this is useful to you.


I would like to share one very useful tip with include_* statements. For example we have two classes first.class.php and second.class.php both located in the same directory (./classes) and first one uses the second one. So we have:

first.class.php
<?php
include_once './second.class.php';
...
?>

also we have file which uses first.class.php:

<?php
include_once './classes/first.class.php';
...
?>

if you will try to execute your script you will get error. Reason: the current directory is different and the relative path in first.class.php (./second.class.php) will be incorrect.

Here is two possible solution I have found:

<?php
include_once dirname(__FILE__).'/second.class.php';
...
?>

or

<?php
chdir(dirname(__FILE__));
include_once './second.class.php';
...
?>

Hope that tip will be useful for some other software developer

Copied from PHP.NET

Gremlyn1
01-13-2010, 08:54 PM
It sounds like the paths are incorrect. Do you have error reporting on?
at the top of your file put

error_reporting(E_ALL);
and see if you get any errors for it
I have E_ALL turned on in my php.ini file, it's weird that I wasn't getting any errors output. The file paths are definitely correct, though, because simply renaming the file works.


Maybe this is useful to you.

Copied from PHP.NET

I did see that, but the only file doing any including/requiring is the index.php. The tables class extends the mysql class so it can directly access database call functions, but that wouldn't have any bearing.

So now the weird thing... I found a snippet on a page somewhere about character encoding of the files and that setting to UTF-8 without BOM made his files work and it seems to have made mine work to... Very odd. I think it actually might be related to the MIME type of the file, not the charaset.

sir.jones
01-13-2010, 09:14 PM
this much be work well:

put your all inlcudes file to the same folder/directory
than replace all to:

<?php
include_once 'second.class.php';
.....
?>

or

<?php
require './yourfoldername/second.class.php';
.....
?>
remove or add yourfoldername, or using ../ and make sure you type all correct file name

or put your complete path/ url and all certain files name here..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum