gpt4 book ai didi

php - file_get_contents 在您自己的本地机器中获取文件

转载 作者:行者123 更新时间:2023-12-03 20:43:52 30 4
gpt4 key购买 nike

我目前正在本地机器上测试我的代码,我希望它能够读取和写入我拥有的文本文件,所以我有以下代码:

Warning: file_get_contents(~/Desktop/insta_user.txt): failed to open stream: No such file or directory in /Users/Brad/Sites/App/src/App/MainBundle/Controller/InstaController.php on line 33

这是我的代码:
$file = '~/Desktop/insta_user.txt';
$current = file_get_contents($file, FILE_USE_INCLUDE_PATH);

该文件已经存在于我的桌面上,只是想知道如何在本地写入该文件。

最佳答案

使用完整路径:

$file = '/Users/yourname/Desktop/insta_user.txt';
$current = file_get_contents($file);

即使网络服务器以您的用户身份运行,它也可能没有相同的环境。

关于php - file_get_contents 在您自己的本地机器中获取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18776779/

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