set_include_path function does not work, PHP 5.2.13 - php

We are using a VPS server in our company and I'm trying to install Roundcube webmail interface
But I can't even get to the configuration phase because the set_include_path function doesn't work and the script can't find the required configuration files.
I get an error like "Fatal Error, ini_set/set_include_path function does not work."
I assume some php settings is causing this but I don't which one.
I'd be glad if I could get some help.
Thanks in advance
//EDIT Here is the codes from the script
ini_set('error_reporting', E_ALL&~E_NOTICE);
ini_set('display_errors', 1);
define('INSTALL_PATH', realpath(dirname(__FILE__) . '/../').'/');
define('RCMAIL_CONFIG_DIR', INSTALL_PATH . 'config');
$include_path = INSTALL_PATH . 'program/lib' . PATH_SEPARATOR;
$include_path .= INSTALL_PATH . 'program' . PATH_SEPARATOR;
$include_path .= INSTALL_PATH . 'program/include' . PATH_SEPARATOR;
$include_path .= ini_get('include_path');
set_include_path($include_path);
require_once 'utils.php';
require_once 'main.inc';

I'm doing this from memory, so it might not be quite right, but I think maybe you are confusing the path and directory separators. There may also be a nicer way to do this than what you are doing (i.e. assembling the whole path at once). Try something like this:
define('INSTALL_PATH', dirname(dirname(__FILE__)));
set_include_path(get_include_path() . PATH_SEPARATOR . INSTALL_PATH . DIRECTORY_SEPARATOR . 'program' . DIRECTORY_SEPARATOR . 'lib');
set_include_path(get_include_path() . PATH_SEPARATOR . INSTALL_PATH . DIRECTORY_SEPARATOR . 'program' . DIRECTORY_SEPARATOR . 'include');
set_include_path(get_include_path() . PATH_SEPARATOR . INSTALL_PATH . DIRECTORY_SEPARATOR . 'program');
Usually I compress this a little bit with implode, since DIRECTORY_SEPARATOR is so verbose:
...PATH_SEPARATOR . implode(DIRECTORY_SEPARATOR, Array(INSTALL_PATH, 'program', 'lib'));
I think by (most importantly) changing some of your PATHs to DIRECTORYs, and (possibly) using incremental get_include_path and set_include_path calls, it will be more readable, portable and just might work properly.

Related

How do I include a path of google client library in php

$r = set_include_path(get_include_path() . '\google-api-php-client-master\src');
echo $r;
require_once 'Google/Client.php';
require_once 'Google/Service/AdExchangeSeller.php';
function __autoload($class_name) {
include 'examples/' . $class_name . '.php';
}
when I am running it on browser its showing following error..
You are not using the path seperator when calling set_include_path, try this:
$r = set_include_path(get_include_path() . PATH_SEPARATOR . '\google-api-php-client-master\src');
Here is the documentation on set_include_path
Edit
Did you restart Apache after making the change to your php.ini?

Javascript error on TinyMCE

I'm encountering a javascript error in a TinyMCE dialogue box when I try to insert a file into content. here's what I get: Uncaught typeError: Cannot read property 'length' of undefined ####.com/editor/jscripts/tiny_mce/plugins/Archiv/php/fileLoader.php?file=javascript 165
Initially I assumed the path was broken so I went over my links and realized everything was fine. I assumed it might have been a browser compatibility issue but tests on Safari, Firefox and even, sadly, IExplorer proved this wasn't the case. I then assumed the fault could have been with my version of TinyMCE and patched it with new files to no success. I'm at wits end! Please help, anyone.
This is the fileLoader.php:
<?php
switch($_GET['file']){
# Javascript files
case 'javascript':
header('Content-type: text/javascript');
readfile('..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'tiny_mce_popup.js')."\r\n\r\n";
readfile('..' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'flash_detect_min.js')."\r\n\r\n";
readfile('..' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'jquery' . DIRECTORY_SEPARATOR . 'jquery-1.3.2.min.js')."\r\n\r\n";
readfile('..' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'jquery' . DIRECTORY_SEPARATOR . 'jquery-ui-1.7.2.custom.min.js')."\r\n\r\n";
readfile('..' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'SWFupload' . DIRECTORY_SEPARATOR . 'swfupload.min.js')."\r\n\r\n";
readfile('..' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'json2.min.js')."\r\n\r\n";
readfile('..' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'SWFupload' . DIRECTORY_SEPARATOR . 'handlers.min.js')."\r\n\r\n";
readfile('..' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'archiv.min.js');
break;
# default 404
default:
header("HTTP/1.0 404 Not Found");
break;
}
?>
It sounds like the PHP is functioning as intended. The error you're mentioning is a Javascript error, as PHP does not use .length you won't see the error get length of undefined come from PHP.
Try including all of your JS files manually and see where the error is. It's likely one of the libraries is expecting an element to be on the page that isn't. If they're minified I would recommend using Source Maps.

PHP Autoload ignorecase

Is there any way to call require_once with some "case insensitive flag" ?
In windows it's okay, but linux is case sensitive. Is there any way to override ?
Thanks
Sure, load
strtolower($className . ".php")
and name your files in lowercase.
Regardless of how you try to load your files, only the lowercase version will ever be loaded.
Just include some where else in you header.php or some other common file.,
<?php
$filename = basename($_SERVER['SCRIPT_FILENAME']);
$request = basename($_SERVER['SCRIPT_NAME']);
if($filename != $request)
die('Case of filename and request do not match!');
?>
I think this may help you resolve your problem. also refer the following location https://superuser.com/questions/431342/linux-both-case-sensitive-and-case-insensitive-and-always-inconvenient
You can use this every time you are loading you auto load the appropriate classes. yu have to change the directories depends on you project. you can you the echo or print_r to print what classes are loaded every time when you are calling something. also all you class names must ot have the same format for example, className.class.php e.g Dashboard.class.php, Category.class.php. you can use
ucwords to make the first letter capital.
function __autoload($className)
{
if (file_exists(__DIR__ . '/../library/' . strtolower($className) . '.class.php'))
{
require_once(__DIR__ . '/../library/' . strtolower($className) . '.class.php');
}
else if (file_exists(__DIR__ . '/../application/controllers/' . strtolower($className) . '.php'))
{
require_once(__DIR__ . '/../application/controllers/' . strtolower($className) . '.php');
}
else if (file_exists(__DIR__ . '/../application/models/' . strtolower($className) . '.php'))
{
require_once(__DIR__ . '/../application/models/' . strtolower($className) . '.php');
}
}

Zend Framework - How to Properly set Include Path?

I'm trying to install TheStudio application which was apparently written using Zend Framework. My test server is running Ubuntu 12.04 and my application directory is stored in /home
My error log is stating
PHP Fatal error: require_once(): Failed opening required 'usr/share/php/libzend-frameworkphp/Zend/Loader/Autoloader.php'
(include_path='.:../library:../application/db:../application/models:../application/utils:../application/views/helpers:../application') in /home/application/config/config.php on line 22
Line 22 of config.php states:
require_once '/usr/share/php/libzend-framework-php/Zend/Loader/Autoloader.php';
The include path is as follows:
define('PS', PATH_SEPARATOR);
define('DS', DIRECTORY_SEPARATOR);
define('ROOT_DIR', dirname('home'));
// Modify include path
$paths = '.' . PS . '..' . DS . 'library'
. PS . '..' . DS . 'application' . DS . 'db'
. PS . '..' . DS . 'application' . DS . 'models'
. PS . '..' . DS . 'application' . DS . 'utils'
. PS . '..' . DS . 'application' . DS . 'views' . DS . 'helpers'
. PS . '..' . DS . 'application';
ini_set("include_path", $paths);
How should I modify the path statement to target the files located in /home directory? Are there other adjustments that should be made in order to resolve the above error?
/usr/share/php/libzend-frameworkphp is the default installation path for the Zend Framework Ubuntu package, so it seems this application is assuming that will be there. sudo apt-get install zend-framework should solve that problem.
I would say it's bad practice to include the full path on a require_once call, and there are way too many include paths being defined on your third code example (which I assume is from the app?).

Strange behaviour for spl_autoload on phpfog

I'm just trying to build my first app on PHP Fog but there's a piece of code that doesn't run properly - works fine on localhost and other regular hosts though.
I use a modified version of TinyMVC, this is the code responsible for setting up autoloading:
/* Set include_path for spl_autoload */
set_include_path(get_include_path()
. PATH_SEPARATOR . FRAMEWORK_BASEDIR . 'core' . DS
. PATH_SEPARATOR . FRAMEWORK_BASEDIR . 'libraries' . DS
. PATH_SEPARATOR . FRAMEWORK_APPLICATION . DS . 'controllers' . DS
. PATH_SEPARATOR . FRAMEWORK_APPLICATION . DS . 'models' . DS
);
/* File extensions to include */
spl_autoload_extensions('.php,.inc');
/* Setup __autoload */
$spl_funcs = spl_autoload_functions();
if($spl_funcs === false)
spl_autoload_register();
elseif(!in_array('spl_autoload',$spl_funcs))
spl_autoload_register('spl_autoload');
Basically, it fails at the first class it should load, which is located in "FRAMEWORK_BASEDIR . 'core' . DS". The class filename is "framework_controller.php" and class name is "Framework_Controller" (tried lowercase as well). If I include the class manually it works but fails with autoload.
Here's the error message that I get:
Fatal error: spl_autoload(): Class Framework_Controller could not be loaded in /var/fog/apps/app7396/claudiu.phpfogapp.com/application/controllers/home.php on line 12
Any ideas as to what could the problem be?
I managed to sort it out:
function framework_autoload($className, $extList='.inc,.php') {
$autoload_paths = array (
FRAMEWORK_BASEDIR . 'core' . DS,
FRAMEWORK_BASEDIR . 'libraries' . DS,
FRAMEWORK_APPLICATION . DS . 'controllers' . DS,
FRAMEWORK_APPLICATION . DS . 'models' . DS
);
$ext = explode(',',$extList);
foreach($ext as $x) {
foreach ($autoload_paths as $v) {
$fname = $v . strtolower($className).$x;
if(#file_exists($fname)) {
require_once($fname);
return true;
}
}
}
return false;
}
spl_autoload_register('framework_autoload');
Thanks to another question here on StackOverflow: spl_autoload problem

Categories