Jump to content

PHP Cannot Create File- Permission denied


us2guys

Recommended Posts

Hello Everyone,I hope someone can help me get around an error I'm running into. I'm using an HTML form (or trying to) to capture user input then a PHP script to create and write to a file based on that input. However I keep getting the following error:Warning: fopen(********@gmail.com.txt) [function.fopen]: failed to open stream: Permission denied in D:\Hosting\6078366\html\register.php on line 10My HTML and PHP code is as follows:*****HTML*****<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title>Register</title>></head><body><h2>Register</h2><form action="register.php" method="post">Email: <input name="email" type="text"><br> <small style="font-style: italic; color: rgb(51, 51, 255);">Thiswill be your username.<br> </small><br>Password: <input name="password1" type="text"><br>Repeat Password: <input name="password2" type="text"> <br>First Name: <input name="firstName" type="text"><br>Last Name: <input name="lastName" type="text""><br> <br> <input value="Register Account" type="submit"></form></body></html>******************PHP*****<html><body><?php$email = $_POST['email'];$password1 = $_POST['password1'];$password2 = $_POST['password2'];$firstName = $_POST['firstName'];$lastName = $_POST['lastName'];$fileToCreate = $email . ".txt";$fileToCreateHandle = fopen($fileToCreate,'w') or die("can't create file");if($password1!=$password2){echo "Your passwords do not match!";fclose($fileToCreate);} else {fwrite($fileToCreateHandle,$email\n);fwrite($fileToCreateHandle,$password1\n);fwrite($fileToCreateHandle,$firstName\n);fwrite($fileToCreateHandle,$lastName\n);fclose($fileToCreate);echo "Thank you, " . $firstName . " " . $lastName . ", for registering with Us2Guys.<br /><br/>";echo "Your username is: " . $email . "<br/>";echo "Your password is: " . $password1;}?></body></html>************************I host with GoDaddyI am new to PHP and things on the server-side so I don't really understand how to fix this. I do appreciate and help or ideas you may have.Thank you!

Link to comment
Share on other sites

I'm guessing you want to use the site to do something, as opposed to learning how to code.I offered the link with the idea it might help you get the site up quickly and with a good amount of security (depends on the application).If you want to learn how to build sites and applications, check out the 'Head First' books - there's a nice series. They're fun to read and technically accurate.

Link to comment
Share on other sites

are you practicing this on your computer or on a server?It might be because you're using the email as the file name. Characters like @ and . might be invalid for creating files names. Try calling it something else instead, like test.txt or something like that. Also keep in mind where this file be relative to the php file.

Link to comment
Share on other sites

"If PHP has decided that filename specifies a local file, then it will try to open a stream on that file. The file must be accessible to PHP, so you need to ensure that the file access permissions allow this access. If you have enabled safe mode, or open_basedir further restrictions may apply. "this quotation is from the php manualsearch for fopen in the manual I think you'll find everything you want

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...