Jump to content

Include Path to PHP Support Folder


This topic is 6296 days old. Please don't post here. Open a new topic instead.

Recommended Posts

What's the best way to specify the path for an include statement that gets to the 'PHP Support' folder? So far I've used FileMaker to return the path to it's folder and then built the path from there, then using fm_evaluate() to get the contents of the path from an FM field. This all works, but I suspect I can just use a relative path, ie:

include_once('../xxx/yyy/mycodetoinclude.php');

Anyone know if there is a way to specify this via a relative path to the 'PHP Support' folder, and what it might be?

Link to comment
Share on other sites

I think there are a couple of good solutions. One is to use a custom php.ini file that has the appropriate include path settings. If you put your own php.ini file in the PHP Support folder, then it will be read when the plug-in starts up (otherwise the default settings are used).

Another option is to use PHP's set_include_path function at the start of your script. Here's some code that doesn't require you to create a FileMaker field and is also cross-platform. You could include this at the top of your PHP code and you might even create a FileMaker custom function that executes this code and thus makes it easier to include.


// here we store a FileMaker calc that will evaluate to the path of the PHP Support folder

$include_path_expression = 'Let (

    [

        platformIsMac = If ( Abs ( Get ( SystemPlatform ) ) = 1 ; 1 ; 0 ) ;

        fileMakerPath = Get ( FileMakerPath )

    ] ;

    If ( platformIsMac ;

        Right ( fileMakerPath ; Length ( fileMakerPath ) - Position ( fileMakerPath ; "/" ; 1 ; 2 ) + 1 ) ;

    //else

        Right ( fileMakerPath ; Length ( fileMakerPath ) - 1 )

    )

) & "Extensions/PHP Support/"';



// now we use fm_evaluate to get FileMaker to return the results of our calc

$include_path = fm_evaluate($include_path_expression);



// here we set the include path

set_include_path($include_path);



// and we echo it out to show it's been set correctly

echo "Include path: " . get_include_path() . "nn";



// now assuming there's a file named 'include_test.php' in the PHP Support folder, this code will execute successfully

include('include_test.php');

Link to comment
Share on other sites

Thanks Micah, but is there a way to do this with a relative path or perhaps have you guys ship the php.ini file so that it's configured to point to the support folder? I'm trying to avoid that 'blob' of code in every piece of code that I'll execute from within FileMaker. Just doesn't look pretty, yanno? :

It would seem that pointing the default include path to the support folder instead of the top level of the hard drive would make more sense...

Edited by Guest
Link to comment
Share on other sites

The problem I see is that we don't know the exact path, for example, it could be FileMaker 8 or 8.5 and for each it could be Advanced or not. We also have both OSX and Windows to consider. There's also the possibility that FileMaker is installed in a non-standard location. And eventually, FileMaker 9 will be out.

Anyway, yes we could compile the plug-in with the typical location of the PHP Support folder but I'm not sure I'd want to write code that depends on this. Personally, I think it's better to be sure by setting the include path dynamically.

I agree with you regarding not wanting to type this each time so how about creating a custom function to store a snippet of code that could easily be accessed?

Link to comment
Share on other sites

Well, I guess I was trying to understand why the top level of the hard disk is a better choice than setting the support folder as the default path. I understand that it may not be there, but if we're writing code to do an include, it seems a logical place where we're going to put PHP code. I think it falls on the developer to make sure that folder is there with the required code; all I'd like to see is that you guys set that as the default if it exists. It eliminates the same code in our tables/scripts/PHP and also eliminates us from having to worry about constructing a textual path to this folder.

Regardless, I've boiled down your example so that I can now do the following:

set_include_path(fm_evaluate('GetField("MyTable::PHPSUPPORTFOLDERPATH")'));




Where MyTable::PHPSUPPORTFOLDERPATH is a calcuated field that contains your above code to return the path to the support folder. Now I can simply do:




include_once('myextracode.php');

To include files from the PHP Support folder.

Link to comment
Share on other sites

We're looking into a way to dynamically determine the correct path to the PHP Support folder when the plug-in starts up and then append it to the include path. I think this would be the best solution because then the path will always be correct no matter where FM is installed or which version or platform you're using. I'll keep you posted.

Link to comment
Share on other sites

We were able to get this to work. We now add the PHP Support folder path to the include_path setting. You can still use a custom php.ini file with your own include path settings and the plug-in will simply add the support folder path to the end. Thanks for your question, I think this is a nice little addition...

Link to comment
Share on other sites

This topic is 6296 days old. Please don't post here. Open a new topic instead.

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

Important Information

By using this site, you agree to our Terms of Use.