PHP:出于安全原因,readfile() 已被禁用

发布于 2025-01-05 22:03:15 字数 163 浏览 0 评论 0 原文

我编写了一个 php 脚本,它使用 readfile($htmlFile); 在屏幕上输出 html 文件。 然而,在我购买的网络托管中,出于安全原因,readfile() 已被禁用。 是否有 readfile() 的替代品(其他 php 函数),或者我别无选择,只能要求管理员为我启用它?

谢谢

I wrote a php script which outputs html files on the screen which uses readfile($htmlFile);
however in the web-hosting that I have purchased the readfile() has been disabled for security reasons.
Is there any substitution ( other php functions) for the readfile() or I have no choice but to ask the admin to enable it for me?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

新一帅帅 2025-01-12 22:03:15

您可以使用以下方法检查哪些功能被禁用:

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

或者您可以使用 file()

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

我不会推荐这种方法,但如果没有效果......

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

You can check which functions are disabled by using:

var_dump(ini_get('disable_functions'));

You can try to use fopen() and fread() instead:

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);
}

Or fopen() with fpassthru()

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

Alternatively you can use fwrite() to write content.


You can also try to use file_get_contents()

http://nl2.php.net/file_get_contents

Or you can use file()

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

I wouldn't recommend this method though, but if nothing works...

$data = file($filename);
if ( $data !== false ) {
    echo implode('', $data);
}
焚却相思 2025-01-12 22:03:15

如果它被禁用,那么您可以执行以下操作作为替代:


$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

希望它有帮助

If its disabled then you could do something like following as alternative:


$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

Hope it helps

护你周全 2025-01-12 22:03:15

您可以尝试:

$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;

You can try :

$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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文