Mao*_*any 2 php php-safe-mode safe-mode readfile
我将我的网站托管在共享主机上,最近将服务器更改为安全模式(甚至没有通知).我使用一个从服务器下载文件的功能,使用readfile()函数(我使用php).现在,在safe_mode中,此函数不再可用.是否有替代或解决方法来处理用户可以下载文件的情况?
谢谢
正如我在评论中所写,readfile()通过将其包含在disable_functions php.ini指令中来禁用它.它与安全模式无关.尝试检查哪些功能被禁用,看看是否可以使用任何其他文件系统函数(-s)来执行readfile()操作.
要查看已禁用的功能列表,请使用:
var_dump(ini_get('disable_functions'));
Run Code Online (Sandbox Code Playgroud)
您可以使用:
// for any file
$file = fopen($filename, 'rb');
if ( $file !== false ) {
fpassthru($file);
fclose($file);
}
// for any file, if fpassthru() is disabled
$file = fopen($filename, 'rb');
if ( $file !== false ) {
while ( !feof($file) ) {
echo fread($file, 4096);
}
fclose($file);
}
// for small files;
// this should not be used for large files, as it loads whole file into memory
$data = file_get_contents($filename);
if ( $data !== false ) {
echo $data;
}
// if and only if everything else fails, there is a *very dirty* alternative;
// this is *dirty* mainly because it "explodes" data into "lines" as if it was
// textual data
$data = file($filename);
if ( $data !== false ) {
echo implode('', $data);
}
Run Code Online (Sandbox Code Playgroud)