stopfocus Posted January 8, 2010 Share Posted January 8, 2010 This is something about the fopen() function thats bugging me. If I make a call to fopen() using the 'a' mode, everything I have read says that it will create a file if it dosn't exsist and appened it if it does. When I use Mode 'a' if the file already exsists it adds white space to the end of the files name creating a new file. For example if I use fopen() to appened to a file named bob.html and it exsists it instead makes a new file , named bob .html, and writes to that. I can fix this problem using mode a+ and then it will appened info to the file instead of creating a new one. Is this how Php is supposed to fundtion are is it a bug? Quote Link to comment https://forums.phpfreaks.com/topic/187684-fopen/ Share on other sites More sharing options...
cags Posted January 8, 2010 Share Posted January 8, 2010 That doesn't sound right, can you show us an example usage that performs that behaviour. Quote Link to comment https://forums.phpfreaks.com/topic/187684-fopen/#findComment-990842 Share on other sites More sharing options...
stopfocus Posted January 10, 2010 Author Share Posted January 10, 2010 The following the part of relevant code * if the mode is set to a the code gives the error stated at beggining of post ////////////////////////////////////////////////////////////////////// if ($submit==submit){ #form ready to be sent $valid=true; #Validates fields have been submited if (empty($name)){$no_name=true; $valid=false;}; if (empty($email)){$no_email=true; $valid=false;}; if (empty($confirm)){$no_confirm=true; $valid=false;}; if (empty($text)){$no_text=true; $valid=false;}; #Validates is email and email conformation validate if ($val){$email_validation=true;$valid=false;}; if ($email !== $confirm){$no_confirm=true; $valid=false;}; if ($valid) {echo 'file written'; $file=fopen("//home/on/therange/$email.html",'a+'); fwrite($file,$body); } else {echo 'form incomplete';}; } Quote Link to comment https://forums.phpfreaks.com/topic/187684-fopen/#findComment-992191 Share on other sites More sharing options...
corbin Posted January 10, 2010 Share Posted January 10, 2010 Hrmmm, there are only two things I can think of: -//home should be /home unless you really are trying to access the path //home -Unless there's a major bug (and there's not), the whole a/a+ adding a space to the name thing doesn't seem likely. Perhaps you should just run trim on $email? Quote Link to comment https://forums.phpfreaks.com/topic/187684-fopen/#findComment-992216 Share on other sites More sharing options...
PFMaBiSmAd Posted January 10, 2010 Share Posted January 10, 2010 How about investigating what is in $email when your code runs? Does var_dump($email) show one extra character, beyond the visible characters, for the length? Where and what is $email being set from and what processing is your code doing on it that could be adding a character to the end of it? Quote Link to comment https://forums.phpfreaks.com/topic/187684-fopen/#findComment-992227 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.