file_get_contents在您自己的本地计算机中获取文件

I am currently testing my code on my local machine and I wanted it to be able to read and write to a text file I have so I have the following code:

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

Here's the code that I have:

$file = '~/Desktop/insta_user.txt';
$current = file_get_contents($file, FILE_USE_INCLUDE_PATH);

The file already exists on my desktop, just wondering how I can write to this file locally.

Use a complete path:

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

Even if the webserver is running as your user it might not have the same environment.