[php-src] Issue #14886: file_put_contents does not work, but it works when checked with file_exists beforehand.
| From: | The-2S | Date: | Tue, 09 Jul 2024 02:19:17 +0000 |
| Subject: | [php-src] Issue #14886: file_put_contents does not work, but it works when checked with file_exists beforehand. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247258@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/14886
Author: The-2S
### Description
Hello,
This may not be the place for this, this may not be a bug.
There may also be a situation specific to the relevant machine.
However, no matter what, it is a subject that I have difficulty coming up with ideas about.
The following code:
```php
<?php
$filePath = $_SERVER['DOCUMENT_ROOT'] . '/test.txt';
$fileContent = 'Test';
file_put_contents($filePath, $fileContent);
```
Resulted in this output:
```
......failed to open stream: No such file or directory in /mypath/test.txt on line .....
```
But I expected this output instead:
```
// There is a relevant file. It shouldn't make any mistakes.
```
ATTENTION:
When I do the above code that doesn't work like this, it works as it should without any errors
(Just added file_exists.):
```php
<?php
$filePath = $_SERVER['DOCUMENT_ROOT'] . '/test.txt';
$fileContent = 'Test';
if(file_exists($filePath)){
file_put_contents($filePath, $fileContent);
}
```
And
The code that gives the error (without file_exists) does the following: If test.txt contains
content, it deletes it and makes the file 0 bytes
I did not encounter this problem when I tried it on other servers, but I could not find this exact
PHP version on them.
Disk space has been checked.
The existence of the file has been checked.
Working and non-working codes were tested many times on the same machine. The results are the same.
There may also be a machine related problem here. As I said, I couldn't find the exact same
version.
I'm very curious about the reason for this situation, that's why I'm writing here.
### PHP Version
PHP 8.1.27
### Operating System
Redhat Linux GNU (shared server) Karnel: 4.18.0-513.9.1.el8_9.x86_64