Jump to content

[SOLVED] I just cannot get 'include' to work.


pk-uk

Recommended Posts

Here is the code:

 


$filename = '/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php' ;
if (file_exists($filename)) {
    echo "The file $filename exists    ";
} else {
    echo "The file $filename does not exist     "; }

$ipath = get_include_path() ;
echo "The include path is: $ipath      "  ;

if ((require '/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php') == "OK" ) 
     {require '/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php' ;
 echo "Include worked" ;}
else
     {echo 'Failed to include' ; }

 

and this is the output:

 

The file /usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php exists

The include path is: .:

Failed to include

 

 

Any help greatly appreciated. PHP is v5.2.1

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/85457-solved-i-just-cannot-get-include-to-work/
Share on other sites

Shouldn't $filename = '/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php' ; be:

 

$filename = "/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php" ;

 

??

Isn't it "" quotes for text and ' ' for numbers right?

Shouldn't $filename = '/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php' ; be:

 

$filename = "/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php" ;

 

??

Isn't it "" quotes for text and ' ' for numbers right?

 

No, string can be within single or double quotes, numbers (integers) should never be surrounded by quotes.

 

require does not return the string "OK". Your test is faulty.

 

Have you tried actually using the Smarty class your including? Given an absolute path like that there is no reason why require won't work.

$filename = '/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php' ;
if (file_exists($filename)) {
    echo "The file $filename exists    ";
} else {
    echo "The file $filename does not exist     "; }

 

Is correct, however, the last part is just :?

 

after the above code, just either include() or require() your file, and go from there.

 

Thanks guys - appreciate the help.

 

(1) no, I didn't set the path name in php.ini - I don't have access and don't want to over-ride.

 

(2) The == OK bit should work, I think.  See example 4 here: http://uk3.php.net/manual/en/function.include.php

 

Nevertheless, given the reply above I removed it and have got it to work - sort of.  By that I mean I have included a file, but now have problems with an include embedded in another include.  However, this has made my head hurt and it's past midnight here.  I'll investigate tomorrow.

 

Thanks again for very prompt attention.

(2) The == OK bit should work, I think.  See example 4 here: http://uk3.php.net/manual/en/function.include.php

 

That example demonstrates the file being included returning the value "OK", not the call to include itself.

 

....  which is what I'd thought I'd done:

 

if ((require '/usr/local/psa/home/vhosts/sub.some_site.co.uk/httpdocs/smarty/libs/Smarty.class.php') == "OK" )

 

How should I have coded it?  Is there a significance in my use of double, rather than single quotes?  Retrospectively it seems that that's the only fundamental difference between my code and the example (barring I'm using require rather than include - though, the manual says they are fundamentally the same).

 

I ask because I'm not that experienced in the use of PHP and often get into a muddle with the concepts  :(

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.