|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51433 file_put_contents() doesn't overwrites a existent file
Submitted: 2010-03-30 02:59 UTC Modified: 2013-02-18 00:34 UTC
Avg. Score:4.2 ± 0.7
Reproduced:3 of 5 (60.0%)
Same Version:2 (66.7%)
Same OS:0 (0.0%)
From: ggens at gmail dot com Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 5.3.2 OS: Windows XP SP3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: ggens at gmail dot com
New email:
PHP Version: OS:


 [2010-03-30 02:59 UTC] ggens at gmail dot com
PHP Version: 5.3.1 installed from Zend Server CE (This option is not present in dropdown menu)

=== Begin of Short Script ===

$file = file_get_contents( 'path/to/my/file' );

// ...

if( ! file_put_contents( 'file/to/be/created', $file ) ) {
    // LOG

=== End of Short Script ===

I've made all necessary routines to grab the content file correctly. If I change the content of file and refresh the page, I can see the changes (with print, echo or var_dump)

But, no matter how many times I change the content and I refresh the page, the content of the created file doesn't changes.

The only way to overwrite the file is restarting my PC. And the content is only overwritten at the first try. After some tries, I got the same "static" content.

And more. Even if I remove the file, manually or by script, the File's Creation Date still the same as the date of the first call of file_put_contents() (currently, 28.03.2010).

If I change the name of file to be created, the updated content is created succesfully. Another content change and page refresh, and the created file still with the same content.

Test script:
The base script is the Short Script posted above, the difference is, in my files, it is separate in factory and adapter classes.

Expected result:
Well, the existent file with updated content, as in the source file.

Actual result:
At the first try, after turn on the computer, the content is updated. All the tries after the first one, he content doesn't changes.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-30 11:16 UTC]
-Status: Open +Status: Feedback
 [2010-03-30 11:16 UTC]
Can you try a small script using CLI?
 [2010-03-30 13:34 UTC]
And please use our PHP builds. For support for Zend Server please got to Zend.
 [2010-03-30 13:42 UTC] imaggens at gmail dot com
I don't know how to use CLI, and it's not a Zend Server problem.
 [2010-03-30 13:57 UTC]
Open a console:

cd c:\where\is\php
php.exe yourscript.php
 [2010-03-30 13:59 UTC]
And enable the error_reporting and show error as well, as I'm pretty sure you get a nice error message (permissions or stmg like that). Alternatively check your error log.

If you don't how to do it, please go to the Zend support forums or to the PHP general mailing list.
 [2010-03-30 15:07 UTC] imaggens at gmail dot com
Well, the CLI results:

== Begin CLI Code ==


ini_set( 'display_errors', TRUE );

error_reporting( E_ALL | E_STRICT );

$path = 'C:\Arquivos de programas\Zend\Apache2\htdocs\ca\library\Insight\FileSystem\File\Adapter/PHP/Templates\CLASS';

$file = 'C:\Arquivos de programas\Zend\Apache2\htdocs\ca\users\Insight\test.php';

file_put_contents( $file, file_get_contents( $path ) );


== End CLI Code ==


When the file in $file doesn't exist, the file is created succesfully.
When the file already exist, no matter how many times I run the code under CLI, the content of file doesn't changes.

Expected Results

Content of file updated.

Extra Information

The presence of two types of slashes doesn't affects the result. Even I replace all '/' by '\' (Windows Slash) the results are the same.
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Mar 09 08:01:24 2021 UTC