Setting Dir and URL Properties

To configure the WysiwygPro file manager and some other features you are required to specify directory paths and URLs for folders. Here are some tips for dynamically setting these paths so that you do not need to hard-code directories and URLs into your application.

Setting file paths 

These properties typically end in Dir, e.g. imageDir. Config variables typically end in _DIR, e.g. WPRO_THEME_DIR.

These are not URLs, they are the absolute file system path to a file or folder. A good trick for setting these is to make use of PHP's __FILE__ magic constant and dirname function. 

The __FILE__ constant always contains the absolute file path of the current PHP file. If used inside an include, the name of the included file is returned.

The dirname function takes a path as it's paramater and returns the parent directory.

For example this gives us the path of the folder in which the current PHP file resides:

$path dirname(__FILE__);

You can wrap dirname calls to get the path of higher level directories. For example this gives us the path of the folder up from the parent folder:

$path dirname(dirname(__FILE__));

Example:
If the wysiwygPro folder is in the same directory as your script and your image folder is also in the same directory as your script then you could use the following to set the imageDir property:

$editor->imageDir dirname(__FILE__).'/images/';

Setting URLs

These properties typically end in URL, e.g. imageURL. Config file variables typically end in _URL, e.g. WPRO_THEME_URL.

URL settings such as the imageURL property should be set to the URL you would type into a browser to navigate to the required file or folder, however there is no need to include the domain name, but it doesn't hurt if you do.

Dynamically setting URLs is not always reliable, for this reason it is best for your application to prompt the user to enter the application's URL during it's installation routine. You can then set URL properties for WysiwygPro based upon your application's configuration settings.

If you cannot set URLs based upon configuration settings then it might help to use PHP's $_SERVER['SCRIPT_NAME'] super global variable. This variable holds the URL of the current PHP script. (Note: It is not affected  by included files like the __FILE__ constant.) The URL is usually absolute from the root of your website (i.e. it does not include the domain name).

Once again we can use the dirname function to find parent directories. For example this gives us the URL of the folder containing the current PHP script:

$URL dirname($_SERVER['SCRIPT_NAME']);

Example:
If the wysiwygPro folder is in the same directory as your script and your image folder is also in the same directory as your script then you could use the following to set the imageURL property:

$editor->imageURL dirname($_SERVER['SCRIPT_NAME']).'/ima