...

View Full Version : require and constants



Chris-2k
08-01-2012, 03:18 PM
here's my init.php:

<?php

ob_start();
session_start();

$hostname = 'localhost';
$database = 'script';
$username = 'user';
$password = '';

$err = 'DB Problem';

$connect = mysql_connect($hostname, $username, $password);
mysql_select_db($database) or die($err);

define('ROOT', (dirname(__FILE__)));

/*** Include the config file ***/
if(!@require_once(dirname(__FILE__).'/config.php')) die('Can\'t find config.php');

/*** Include the functions file ***/
if(!@require_once $_SERVER['DOCUMENT_ROOT'] .'/includes/functions.php') die('Can\'t find functions.php');


if(!@require_once $_SERVER['DOCUMENT_ROOT'] .'/includes/template.func.php') die('Can\'t find template.func.php');;
?>

here's config.php

<?php
/********************************************

IMG-ize Script 2012
@version: 3.0

@auth0or: Chris Reynolds

Copyright 2012 Chris Reynolds

********************************************/

$config['theme_folder_name'] = 'MrOSX';

$config['site_address'] = 'http://www.thishosting.org'; // No slash
$config['site_path'] = $_SERVER['DOCUMENT_ROOT'];
$config['site_email'] = 'webmaster@1domain.com';

$config['upload_destination'] = 'i293';
$config['thumb_destination'] = 'thumbs';

$config['site_theme'] = 'content/themes/MrOSX';
$config['site_name'] = 'ImgIze Script';
$config['site_desc'] = 'i293';


ini_set("memory_limit","80M");

$config['max_width'] = 1900;
$config['max_height'] = 1900;
$config['max_filesize'] = 419304; // Bytes only

$config['multi_upload'] = true; // true or false
$config['modules_enabled'] = true; // true or false
$config['maintenance_mode'] = false; // true or false
$config['facebook_comments'] = true ; // true or false

$config['facebook_app_id'] = 'test'; // Get your app id on http://developers.facebook.com/apps

$config['acp_password'] = 'password89';

$config['allowed_mime_types'] = array(
'image/gif',
'image/jpeg',
'image/png',
'image/bmp' ); // allowed image types, to add more use: 'image{type}',

##################################################### DO NOT EIT BELOW... #####################################################

define('THEME_DIR', 'content/themes/' . $config['theme_folder_name'] .'/');
define('CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] .'/content/');
define('INCLUDES_DIR', $_SERVER['DOCUMENT_ROOT'] .'/includes/');

?>

the constants aren't working now i've updated vars to constants, here's sme errors:




Warning: include_once(INCLUDES_DIRinit.php) [function.include-once]: failed to open stream: No such file or directory in /home/sonicimg/public_html/index.php on line 13

Warning: include_once() [function.include]: Failed opening 'INCLUDES_DIRinit.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/sonicimg/public_html/index.php on line 13

Warning: include(THEME_DIRindex.php) [function.include]: failed to open stream: No such file or directory in /home/sonicimg/public_html/index.php on line 15

Warning: include() [function.include]: Failed opening 'THEME_DIRindex.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/sonicimg/public_html/index.php on line 15


eg im calling stuff like this
function include_themeHeader($theme) {
include THEME_DIR .'header.php';
}

can ya help?

Arcticwarrio
08-01-2012, 04:48 PM
remove the $config bit?


define('THEME_DIR', 'content/themes/' . theme_folder_name .'/');

Arcticwarrio
08-01-2012, 04:49 PM
ignore that i completley read your post wrong lol

AndrewGSW
08-01-2012, 07:48 PM
Warning: include_once(INCLUDES_DIRinit.php)

suggests that your include statement is incorrectly formed; you may have included unnecessary apostrophes:


include_once(INCLUDES_DIR . 'init.php');

Otherwise, it's probably not pointing at the correct location (relative to the current file) - but my first suggestion is more probable.

Fou-Lu
08-01-2012, 07:53 PM
Yes indeed. Problem is that this file has no been included as there is no replacement of the constant in use since it has not been treated as a string.
Post the code in index.php.


BTW, what are you doing with these ifs:


/*** Include the config file ***/
if(!@require_once(dirname(__FILE__).'/config.php')) die('Can\'t find config.php');

You cannot capture a fatal error and therefore cannot trigger a die (suppression will merely prevent it from displaying to the screen. It will still fatally die). I'll have to test when I get home, but I believe that include/require also only return a result on call if a return is provided from the main() of the included script.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum