0

我有这个代码将检查(a)商店是否在线和(b)目录/store是否可用:

<?php

// Set flag that this is a parent file

define( '_JEXEC', 1 );

define('JPATH_BASE', dirname(realpath(__FILE__)). '/../store' );

define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
jimport('joomla.application.module.helper');
jimport('joomla.application.component.helper');


$mainframe =& JFactory::getApplication('site');

$filename = '../store/';

if (!$mainframe->getCfg('offline') && file_exists($filename))
        {
    echo "online";
    }

else 
        {
    echo "offline";
        }
?>

当我在我的控制面板中将商店设置为离线时,它工作正常,但是当目录/store的名称已更改或被删除(变得不可用)时,页面会生成服务器错误,而它应该回显“离线”。我该如何修改它,以便当目录名称更改时,它会更改它以回显“离线”

4

1 回答 1

0

您必须在应用程序初始化之前检查目录,因为应用程序依赖于目录的存在。

<?php

// Set flag that this is a parent file
define( '_JEXEC', 1 );

define('JPATH_BASE', dirname(realpath(__FILE__)). '/../store' );
if (!file_exists(JPATH_BASE)) {
    echo 'Offline due to missing installation';
    exit(0);
}

define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
jimport('joomla.application.module.helper');
jimport('joomla.application.component.helper');

$app = JFactory::getApplication('site');
if ($app->getCfg('offline')) {
    echo 'Offline due to configuration setting';
    $app->close();
}
echo 'Online';
于 2013-04-30T09:48:39.760 回答