Re: file_get_contents works in base script but not in an included script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 18, 2009 at 03:54:31PM -0600, LinuxManMikeC wrote:

> In PHP4, I am using file_get_contents('file.sql',true) to bring in SQL
> queries from files who's directory is on the include path.  It works
> fine in the main php scripts (ones accessible through URLs), but when
> done in a php script that is included by one of the main scripts I
> just get false instead of a string.  The files exist, the include path
> is correctly set at all times (I've checked), and the exact same code
> works when placed directly in the main php script.  I've been tearing
> through documentation for hours.  Is there some quirk, or setting I'm
> missing?  Below is an example of what I'm doing.
> 
> main.php
> <?php
>   set_include_path(get_include_path . ':/absolute/path/to/sql');
> 
>   include('inc.php');
>   $SQL1 = file_get_contents('query.sql',true);
>   //$SQL1 == contents of query.sql
> ?>
> 
> includes/inc.php
> <?php
>   $SQL2 = file_get_contents('query.sql',true);
>   //$SQL2 == false
>   //My path is still intact here
> ?>

Ten to one, this is a pathing problem in the inc.php script. Make a copy
of the query.sql file and put it in the includes directory. Test. Make a
copy and put it in the document root. Test. At some point it will work,
and you'll know where inc.php expects to find it. Then you can work out
why it expects that. Then you'll grasp the "quirk".

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux