php fwrite writes the file successfully but the file has no content

WBOY
Release: 2023-03-01 20:22:02
Original
2661 people have browsed it

I found a very strange problem. When I used fwrite to write a file, the program did not report an error. fwrite also returned the number of words written, but the content in the file was empty.

<code>        $path = Yii::$app->basePath."/upload/tt.txt";
        $file = fopen($path,'w');
        fwrite($file,'aaaaa');
        fclose($file);</code>
Copy after login
Copy after login

Using the Yii2.0 framework.
Try using file_put_contents again, but still no response O__O "…

Reply content:

I found a very strange problem. When I used fwrite to write a file, the program did not report an error. fwrite also returned the number of words written, but the content in the file was empty.

<code>        $path = Yii::$app->basePath."/upload/tt.txt";
        $file = fopen($path,'w');
        fwrite($file,'aaaaa');
        fclose($file);</code>
Copy after login
Copy after login

Using the Yii2.0 framework.
Try using file_put_contents again, but still no response O__O "…

Please check if the file has writable permissions

It feels like the writing was successful, please look for possible paths.

<code>is_writable($file) 
</code>
Copy after login

Determine write permission

But the author seems to have the wrong path

It should be that the path is written wrong. You can print out $path and have a look

Raise the error level of php and debug it

Please check whether the file encoding format conflicts.

Enter $path and confirm whether the path is correct

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!