文件的内容是否有可能得到的获取位于/ etc /东西用PHP
/etc/asterisk/sip.conf
的内容和使用PHP打印呢?
我想的是:
<?php
$filecontents = file_get_contents("/etc/asterisk/sip.conf");
print $filecontents;
?>
,但它不工作...的文件使用chmod是正确的。
谢谢
文件的内容是否有可能得到的获取位于/ etc /东西用PHP
/etc/asterisk/sip.conf
的内容和使用PHP打印呢?
我想的是:
<?php
$filecontents = file_get_contents("/etc/asterisk/sip.conf");
print $filecontents;
?>
,但它不工作...的文件使用chmod是正确的。
谢谢
但它不工作......我设置了权限。
根据什么不工作,你可能会设置错误的权利。
验证通过验证返回值:
$filecontents = file_get_contents("/ect/asterisk/sip.conf");
if ($filecontents === FALSE)
{
echo "I made an error.\n";
}
else
{
print $filecontents;
}
最有可能你的问题是ect
这是etc
变体,它确实可能存在。要确定文件是否存在,请对其进行测试。完整的代码:
$file = "/ect/asterisk/sip.conf";
if (!is_file) {
echo "The file $file does not exists. Please check the path.\n";
}
if (!is_readable) {
echo "The file $file is not readable. Ensure you can read it.\n";
}
$filecontents = file_get_contents($file);
if ($filecontents === FALSE)
{
echo "I made an error.\n";
}
else
{
print $filecontents;
}
谢谢,我得到这个输入: 注意:使用未定义的常量is_file - 假设'is_file'在/var/www/admin_siptrunks.php在42行注意:使用未定义的常量is_readable - 假设' is_readable'在/var/www/admin_siptrunks.php在线46 – 2013-04-09 15:22:34
我不知道如果这是你的问题,但你写/ect
,而tradicional目录/etc
否则,把这个权利file_get_contents
前:
ini_set("display_errors", 1);
error_reporting(E_ALL);
并检查错误输出
这个整数看起来不是很好用引号括起来:) – 2013-04-09 14:32:44
然而它的工作原理。上帝保佑松散地在PHP中输入变量。 '1 ==“1”== TRUE',但是'1!==“1”!== TRUE' – Korcholis 2013-04-09 14:34:10
是的,它肯定有效,只是那些引号不属于那里。它现在看起来亲:) – 2013-04-09 14:35:03
这主要取决于两个主要权限,如果您的提到的目录路径是正确的。你提到'/ ect',恐怕它可能是你的代码中的一个错字。
我真的很抱歉..我的sip.conf文件是空的,我觉得愚蠢
是的,它非常愚蠢。然而,解释并不值得。祝你好运。 :) – acpmasquerade 2013-04-09 16:14:08
为此后续行动。 – 2013-04-11 11:21:20
会发生什么事时,你试试? – 2013-04-09 14:30:43
如果这是Linux,是不是它应该是'/ etc /'而不是'/ ect /'? – 2013-04-09 14:31:28
是的,对不起,错误,问题是一样的 – 2013-04-09 15:19:02