2013-04-29 65 views
0

我有这样的代码,将检查是否(一)存储联机和(b)的目录/存储可用:如何检查目录是在线PHP

<?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"; 
     } 
?> 

当我设置为脱机在我的控制面板,它工作正常商店,但是,当目录/存储有它的名字更改或删除(不可用)的页面生成服务器错误,而应该回声“离线”。我怎么可以修改它,这样,当目录名称的变化,它的变化呼应“离线”

+0

如果页面抛出服务器错误,我不认为它可以在这段代码中处理。你需要找出的错误被抛出.. – raidenace 2013-04-29 18:49:06

+0

为什么你定义$文件名呢?它在你的不断JPATH_BASE,其中包含一个绝对路径,应者优先定义。毕竟,这会是有趣的,看看您的服务器错误的详细信息(检查PHP日志,因为PHP错误是没有实际的服务器错误)。 – jossif 2013-04-29 19:03:07

回答

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'; 
+0

非常感谢。对迟到的赞赏道歉。 – user2308480 2013-05-12 15:38:06