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
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?

 

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.

Link to comment
Share on other sites

$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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

(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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.