我正在为 Minecraft 服务器制作控制台查看器,但是当我进入只需要在浏览器中显示文本的阶段时,它不会让我出现此错误:
致命错误:第 17 行 C:\xampp\htdocs\testingfile.php 中允许的内存大小为 134217728 字节已用尽(尝试分配 36 字节)
我猜它不会显示因为文件太大?该文件约为 4.5MB。我想显示文件中最近的 10 行。
这是我的代码:
<?php
// define some variables
$local_file = 'C:\Users\Oscar\Desktop\worked.txt';
$server_file = 'NN7776801/server.log';
$ftp_server="Lol.Im.Not.Thick";
$ftp_user_name="Jesus";
$ftp_user_pass="ReallyLongPassWordThatYouWontGuessLolGoodLuckMateGuessingThisPass";
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
$contents = file($local_file);
$string = implode($contents);
echo $string;
for ($i = 0; $i < 6; $i++) {
echo $local_file[$i] . "\n";
}
}
else {
echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);
?>