Bug #72983 [Com]: file_put_contents does not overwrite if file exists

From: Date: Fri, 02 Sep 2016 15:34:20 +0000
Subject: Bug #72983 [Com]: file_put_contents does not overwrite if file exists
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203751@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72983&edit=1

 ID:                 72983
 Comment by:         fernando at null-life dot com
 Reported by:        jim dot michaels at Jesusnjim dot com
 Summary:            file_put_contents does not overwrite if file exists
 Status:             Feedback
 Type:               Bug
 Package:            Filesystem function related
 Operating System:   vista x32 amd
 PHP Version:        7.1.0beta3
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Can't reproduce this issue on a Windows 8 with PHP 7.1 Beta 3 from windows.php.net QA

I tried with a local path and with a SMB remote path:

<?php
error_reporting(E_ALL);
file_put_contents('test.txt', "HOLA");
var_dump(file_get_contents('test.txt') == "HOLA");
file_put_contents('test.txt', "ADIOS");
var_dump(file_get_contents('test.txt') == "ADIOS");

file_put_contents('\\\\server\folder\test.txt', "HOLA");
var_dump(file_get_contents('\\\\server\folder\test.txt') == "HOLA");
file_put_contents('\\\\server\folder\test.txt', "ADIOS");
var_dump(file_get_contents('\\\\server\folder\test.txt') == "ADIOS");


D:\fms\php710beta3>php file.php
bool(true)
bool(true)
bool(true)
bool(true)


Previous Comments:
------------------------------------------------------------------------
[2016-09-01 10:30:41] jmichae3 at yahoo dot com

yes, error reporting was set for E_ALL.
 I cannot compile php. requires languages and utilities I do not have.
I don't have linux.
this is on windows vista.

------------------------------------------------------------------------
[2016-08-31 16:24:20] cmb@php.net

> if file is open in programmer's editor, rw.txt file does not
> refresh.

Is it possible that this editor locks the file? Please enable
error_reporting=E_ALL, and see if there are any warnings shown.

> this could be related with c++ old gcc bug in fstream's
> std::ios_base::creat notworking for while a number of years.

Did you compile the php.exe binary with GCC? The officially
distributed php.exes are compiled with Visual C++.

------------------------------------------------------------------------
[2016-08-31 03:00:07] jim dot michaels at Jesusnjim dot com

Description:
------------
file_put_contents() does not overwrite if file exists. if file exists, file is not touched. if file
is open in programmer's editor, rw.txt file does not refresh. this could be related with c++
old gcc bug in fstream's std::ios_base::creat notworking for while a number of years.


Test script:
---------------
<?php
$a=file_get_contents("\\w\\Jesusnjim\\menu7a.xml");
$a=preg_replace('/\//','\\',$a);
file_put_contents("\\w\\Jesusnjim\\rw.txt", $a);
?>

2nd time:
<?php
$a=file_get_contents("\\w\\Jesusnjim\\menu7a.xml");
$a=preg_replace('/\//','\\\\',$a);
file_put_contents("\\w\\Jesusnjim\\rw.txt", $a);
?>

Expected result:
----------------
expected / to be changed to \\ and for rw.txt to be changed in programmer's editor jedit and to
be notified that file was changed.

Actual result:
--------------
if file is open in programmer's editor, rw.txt file does not refresh.



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=72983&edit=1


Thread (15 messages)

« previous php.bugs (#203751) next »