Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/52990-problem-with-fwrite/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/52990-problem-with-fwrite/#findComment-261771
Share on other sites

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/52990-problem-with-fwrite/#findComment-261779
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.