文件的內容是否有可能得到的獲取位於/ 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