2012-02-15 49 views
1

我寫了一個php腳本,它在使用readfile($ htmlFile)的屏幕上輸出html文件; 然而,在我已購買的網絡託管中,readfile()已因安全原因被禁用。 是否有替代(其他PHP函數)的readfile()或我別無選擇,只能要求管理員爲我啓用它?PHP:readfile()由於安全原因已被禁用

感謝

+0

移動主機,他們顯然不是一個好主意,誰知道他們還殘疾。 – 2012-02-15 08:27:38

+0

這聽起來像是一件奇怪的事情 - 它通常是因爲安全原因而被禁用的system()調用。它是什麼樣的安裝?就我所知,cPanel(一種流行的Linux共享主機系統)並不正常。 – halfer 2012-02-15 10:15:58

+0

順便說一下,是的,與主機取得聯繫 - 並要求他們提供完整的禁用功能列表並將其粘貼到此處。有人會給你一個關於它們是否合理的看法(儘管完全有可能在沒有禁用的情況下運行共享主機,afaik)。 – halfer 2012-02-15 10:16:54

回答

2

您可以檢查哪些功能通過使用禁用:

var_dump(ini_get('disable_functions')); 

你可以嘗試使用fopen()和FREAD()代替:

http://nl2.php.net/manual/en/function.fopen.php

http://nl2.php.net/manual/en/function.fread.php

$file = fopen($filename, 'rb'); 
if ($file !== false) { 
    while (!feof($file)) { 
     echo fread($file, 4096); 
    } 
    fclose($file); 
} 

或者fopen()函數與fpassthru( )

$file = fopen($filename, 'rb'); 
if ($file !== false) { 
    fpassthru($file); 
    fclose($file); 
} 

或者,您可以使用fwrite()寫入內容。


您也可以嘗試使用file_get_contents()函數

http://nl2.php.net/file_get_contents

或者你可以使用文件()

http://nl2.php.net/manual/en/function.file.php

我不會,雖然建議使用這種方法,但如果沒有什麼工作...

$data = file($filename); 
if ($data !== false) { 
    echo implode('', $data); 
} 
1

如果它被禁用,則你可以做類似以下內容作爲替代:

 

$file = fopen($yourFileNameHere, 'rb'); 
if ($file !== false) { 
    while (!feof($file)) { 
     echo fread($file, 4096); 
    } 
    fclose($file); 
} 

//OR 
$contents = file_get_contents($yourFileNameHere); //if for smaller files 
 

希望它可以幫助

1

你可以試試:

$path = '/some/path/to/file.html'; 
$file_string = ''; 
$file_content = file($path); 
// here is the loop 
foreach ($file_content as $row) { 
    $file_string .= $row; 
} 

// finally print it 
echo $file_string; 
相關問題