joehoyle Posted May 25, 2007 Share Posted May 25, 2007 Hi, I have a simple problem, when I try to write to an existing file, fwite creates a duplicate with the same name instead of overwriting the specified file. Any suggestions. Here is my code: $fp = fopen($path,"w+") or die("can't open file"); fwrite($fp,$text); fclose($fp); thanks very much Quote Link to comment https://forums.phpfreaks.com/topic/52990-problem-with-fwrite/ Share on other sites More sharing options...
per1os Posted May 25, 2007 Share Posted May 25, 2007 www.php.net/fopen 'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. 'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. Try just w, it could be opened for reading and writing and that file is locked so when trying to write to it since the file is locked as read-only it will not write to it, not sure if this is true but could be. Quote Link to comment https://forums.phpfreaks.com/topic/52990-problem-with-fwrite/#findComment-261771 Share on other sites More sharing options...
genericnumber1 Posted May 25, 2007 Share Posted May 25, 2007 It can't create a file with the exact same name since no two files can be named exactly the same in the same directory, you'll have to describe your problem more in depth. Quote Link to comment https://forums.phpfreaks.com/topic/52990-problem-with-fwrite/#findComment-261773 Share on other sites More sharing options...
joehoyle Posted May 25, 2007 Author Share Posted May 25, 2007 Hi, I tried changing it to just "w" but didnt make any difference, also genericnumber1: I thought too that you could not have two files with the same name, but Im sitting here looking at too copies of the same file in my ftp browser, I have refreshed the list etc, there are too files there alright, very strange. If I using fwrite to write to a new file, that works, but only the first time, it will not then rewrite that file. The permissions are set to 777 for the file and dir. Quote Link to comment https://forums.phpfreaks.com/topic/52990-problem-with-fwrite/#findComment-261779 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.