gpt4 book ai didi

php - 文件无法使用 PHP fopen 打开

转载 作者:可可西里 更新时间:2023-11-01 12:25:44 25 4
gpt4 key购买 nike

我已经试过了:

    <?php
$fileip = fopen("test.txt","r");

?>

这应该以只读方式打开文件,但它没有test.txt 文件与 index.php(主项目文件夹)位于同一文件夹中

文件打不开

当我像这样输入 echo 时:

echo $fileip;

它回来了

资源编号#3

最佳答案

文件确实打开得很好,你不能那样回显它,因为它是一个文件指针,而不是文件本身的内容。您需要使用 fread() 来读取实际内容,或者更好的是,使用 file_get_contents() 直接获取内容。

按你的方式做:

$handle = fopen("test.txt", "r");
$fileip = fread($handle, filesize($filename));
fclose($handle);

echo $fileip;

或者,使用 file_get_contents():

$fileip = file_get_contents("test.txt");

echo $fileip;

关于php - 文件无法使用 PHP fopen 打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2408614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com