我使用的AcyMailing应用程序接口脚本运行得很好,但只在Joomla根目录下运行-如http://example.com/api.php
但是,如果我将相同的脚本放到相同Joomla下的我自己的目录中,假设是/scripts/api.php -我在第12行有Apache错误
PHP Fatal error: require_once(): Failed opening required '/var/www/html/joomla/scripts/includes/defines.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/joomla/scripts/api.php on line 12
代码中令人困惑的部分是
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
if (file_exists(dirname(__FILE__) . '/defines.php')) {
include_once dirname(__FILE__) . '/defines.php';
}
if (!defined('_JDEFINES')) {
define('JPATH_BASE', dirname(__FILE__));
require_once JPATH_BASE.'/includes/defines.php';
}
第12行的位置
require_once JPATH_BASE.'/includes/defines.php';
如何修复路径,使api.php不仅可以从Joomla根目录运行,还可以从/scripts/api.php运行?
提前感谢您的任何想法尝试。
已编辑-这里是推荐的带有JPATH_SITE的完整脚本-但仍然是一个错误
PHP Fatal error: require_once(): Failed opening required 'JPATH_SITE/includes/defines.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/joomla/scripts/singlemail.php on line 12
可能在下面的完整脚本中遗漏了什么?
<?php
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
if (file_exists(dirname(__FILE__) . '/defines.php')) {
include_once dirname(__FILE__) . '/defines.php';
}
if (!defined('_JDEFINES')) {
define('JPATH_BASE', dirname(__FILE__));
require_once JPATH_SITE.'/includes/defines.php';
}
require_once JPATH_SITE.'/includes/framework.php';
$app = JFactory::getApplication('site');
if(!include_once(rtrim(JPATH_ADMINISTRATOR,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_acymailing'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'helper.php')){
echo 'This code can not work without the AcyMailing Component';
return false;
}
$mailer = acymailing_get('helper.mailer');
$mailer->report = true;
$mailer->trackEmail = true;
$mailer->autoAddUser = false;
$mailer->sendOne(11,'test@example.com');
?>
发布于 2016-11-17 04:57:24
使用JPATH_SITE
例如:http://example.com/mysite/api.php
这里我的网站是子文件夹,在这里你安装joomla,时间JPATH_BASE有一些问题。
例如: 1. http://example.com/mysite/api.php 2. http://example.com/api.php
下面的路径将适用于所有地方,因为JPATH_SITE将找到joomla安装文件夹。
包含定义。“/ require_once /JPATH_SITE”;
https://stackoverflow.com/questions/40640208
复制