Jump to content

fopen()


Recommended Posts

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?

Link to comment
Share on other sites

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';};

}

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
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.