Jump to content

PHP Refuses to open a file when it's clearly there

Hello everybody,

I'm using the Quickbooks Web SDK trying to do a simple invoice query with the example_invoice_query.php file. I keep getting this error:

Quote

/QuickBooks/Utilities.php/QuickBooks/Driver/Factory.php/QuickBooks/Driver/.php
Warning: require_once(/home/autosim/public_html/quickbooks-php-master/QuickBooks/Driver/.php): failed to open stream: No such file or directory in /home/autosim/public_html/quickbooks-php-master/QuickBooks/Loader.php on line 57

Fatal error: require_once(): Failed opening required '/home/autosim/public_html/quickbooks-php-master/QuickBooks/Driver/.php' (include_path='.:/usr/local/lib/php:/home/autosim/automaticsim:/home/autosim/public_html/quickbooks-php-master') in /home/autosim/public_html/quickbooks-php-master/QuickBooks/Loader.php on line 57

 

Here is my file structure:

59556f6ed27be_FileStructure.PNG.ef77b9c76e6688082b3e7ef1e69756da.PNG

 

Here is my Loader file

<?php

/**
 * File/class loader for QuickBooks packages 
 * 
 * Copyright (c) 2010 Keith Palmer / ConsoliBYTE, LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.opensource.org/licenses/eclipse-1.0.php
 * 
 * @package QuickBooks
 * @subpackage Loader
 */

//  
if (!defined('QUICKBOOKS_LOADER_REQUIREONCE'))
{
	define('QUICKBOOKS_LOADER_REQUIREONCE', true);
}

if (!defined('QUICKBOOKS_LOADER_AUTOLOADER'))
{
	define('QUICKBOOKS_LOADER_AUTOLOADER', true);
}

/**
 * 
 */
class QuickBooks_Loader
{
	/**
	 * 
	 */
	static public function load($file, $autoload = true)
	{
		//print('loading file [' . $file . ']' . "\n");
		
		if ($autoload and 
			QuickBooks_Loader::_autoload())
		{
			return true;
		}
		
		static $loaded = array();
		
		if (isset($loaded[$file]))
		{
			return true;
		}
		
		$loaded[$file] = true;
		
		if (QUICKBOOKS_LOADER_REQUIREONCE)
		{
            echo $file;
			require_once QUICKBOOKS_BASEDIR . $file; //<------------- Here is line 56
		}
		else
		{
            echo $file;
			require QUICKBOOKS_BASEDIR . $file;
		}
		
		return true;
	}
	
	/**
	 * 
	 */
	static protected function _autoload()
	{
		if (!QUICKBOOKS_LOADER_AUTOLOADER)
		{
			return false;
		}
		
		static $done = false;
		static $auto = false;
		
		if (!$done)
		{
			$done = true;
			
			if (function_exists('spl_autoload_register'))
			{
				// Register the autoloader, and return TRUE
				spl_autoload_register(array( 'QuickBooks_Loader', '__autoload' ));
				
				$auto = true;
				return true;
			}
		}
		
		return $auto;
	}
	
	/**
	 * 
	 */
	static public function __autoload($name)
	{
		if (substr($name, 0, 10) == 'QuickBooks')
		{
			$file = '/' . str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php';
			QuickBooks_Loader::load($file, false);
		}
	}
	
	/** 
	 * Import (require_once) a bunch of PHP files from a particular PHP directory
	 * 
	 * @param string $dir
	 * @return boolean
	 */
	static public function import($dir, $autoload = true)
	{
		$dh = opendir(QUICKBOOKS_BASEDIR . $dir);
		if ($dh)
		{
			while (false !== ($file = readdir($dh)))
			{
				$tmp = explode('.', $file);
				if (end($tmp) == 'php' and 
					!is_dir(QUICKBOOKS_BASEDIR . $dir . DIRECTORY_SEPARATOR . $file))
				{
					QuickBooks_Loader::load($dir . DIRECTORY_SEPARATOR . $file, $autoload);
					//require_once $dir . '/' . $file;
				}
			}
			
			return closedir($dh); 
		}
		
		return false;
	}	
}

 

Link to comment
Share on other sites

Link to post
Share on other sites

Don't you see that slash just before .php extension in require path? You're probably insert one slash to much, try to debug your code to find out where it is happening.

Link to comment
Share on other sites

Link to post
Share on other sites

On 6/29/2017 at 5:07 PM, Mr_KoKa said:

Don't you see that slash just before .php extension in require path? You're probably insert one slash to much, try to debug your code to find out where it is happening.

I can't figure out where it's coming from...

Link to comment
Share on other sites

Link to post
Share on other sites

Somewhere where you glue things together using dir separators like:

 

$file = '/' . str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php';

or

QuickBooks_Loader::load($dir . DIRECTORY_SEPARATOR . $file, $autoload);

Try to echo things out and see where it getting wrong.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×