如何检查目录是否在线php

时间:2013-04-29 18:44:31

标签: php joomla

我有这个代码,它将检查(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 更改或删除(变得不可用)时,页面会生成服务器错误< strong>而它应该回应“离线”。我如何修改它,以便当目录名称更改时,它更改它回应“离线”

1 个答案:

答案 0 :(得分: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';