Orio Posted April 13, 2006 Share Posted April 13, 2006 Hello,I have some problems using the fwrite function.What basicly I want to do is insert information that someone sent (with a form) to a txt file.The pages:1) The HTML page (form):[code]<form method=post action="form.php"><b>Your name:</b><br><input type="text" name="Name" size="30"><br><br><br><b>How would you rate?</b><br><br>1<input type=radio name="Rating" value="1"> 2<input type=radio name="Rating" value="2"> 3<input type=radio name="Rating" value="3"> <br><br><br><b>Comments:</b><br><textarea cols="40" rows="10" name="Comments"></textarea><input type="submit" value="Send"><input type="reset" value="Clear the form"></form>[/code]2) The PHP script:[code]$filename = '46.txt';$content = "Name: ".$_POST['Name']." \r\n Rating: ".$_POST['Rating']." \r\n Comments: \r\n ".$_POST['Comments']." \r\n ".$ip." \r\n ------ \r\n \r\n";if (!$handle = fopen($filename, 'ab')){ echo "There was a problem opening the file"; exit;}if (fwrite($handle, $content) === FALSE){ echo "Cannot write to file"; exit;} echo "Thank you!";fclose($handle);?>[/code]But when I submit, I get the following error:Warning: fopen(46.txt): failed to open stream: Permission denied in C:\Inetpub\vhosts\oriosriddle.com\httpdocs\form.php on line 8.Can you help me? I cant find what the problem is.I am hosted in serversea.com, and I dont have any control on the apache or php files. The server runs on Windows.I know I can do it with mysql, but I dont know mysql =/ And its pretty urgent.Thanks,Orio. Quote Link to comment https://forums.phpfreaks.com/topic/7308-fwrite/ Share on other sites More sharing options...
kenrbnsn Posted April 13, 2006 Share Posted April 13, 2006 Does the web server have permission to write to your file?Ken Quote Link to comment https://forums.phpfreaks.com/topic/7308-fwrite/#findComment-26644 Share on other sites More sharing options...
Orio Posted April 13, 2006 Author Share Posted April 13, 2006 I dont know...Is there a way knowing by using phpinfo() or something?EDIT- just went over the info phpinfo() gives, and I cant find anything about writing to files.Orio. Quote Link to comment https://forums.phpfreaks.com/topic/7308-fwrite/#findComment-26650 Share on other sites More sharing options...
wildteen88 Posted April 13, 2006 Share Posted April 13, 2006 [!--quoteo(post=364470:date=Apr 13 2006, 05:24 PM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ Apr 13 2006, 05:24 PM) [snapback]364470[/snapback][/div][div class=\'quotemain\'][!--quotec--]I dont know...Is there a way knowing by using phpinfo() or something?EDIT- just went over the info phpinfo() gives, and I cant find anything about writing to files.Orio.[/quote]What Kan ment was does your file 46.txt have the correct CHMOD settings set, this is nothing to do with how PHP is setup but the permissions on the file(s) you are writting data to. Quote Link to comment https://forums.phpfreaks.com/topic/7308-fwrite/#findComment-26669 Share on other sites More sharing options...
Orio Posted April 13, 2006 Author Share Posted April 13, 2006 Oh, its a normal txt file I created on my computer, and I checked if its writable with the is_writable() function, and it is... Still no idea whats the problem.By the way, I have no idea what CHMOD is... lolThanks again,Orio. Quote Link to comment https://forums.phpfreaks.com/topic/7308-fwrite/#findComment-26691 Share on other sites More sharing options...
earl_dc10 Posted April 13, 2006 Share Posted April 13, 2006 CHMOD is a fancy term for the permissions that you give a file Quote Link to comment https://forums.phpfreaks.com/topic/7308-fwrite/#findComment-26703 Share on other sites More sharing options...
Orio Posted April 15, 2006 Author Share Posted April 15, 2006 Ok, so I tried to do it this way:[code]$filename = '46.txt';$somecontent = "Name: ".$_POST['Name']." \r\n Rating: ".$_POST['Rating']." \r\n Comments: \r\n ".$_POST['Comments']." \r\n ".$ip." \r\n ------ \r\n \r\n";chmod("46.txt", 0644);if (is_writable($filename)){ if (!$handle = fopen($filename, 'ab')) { echo "There was a problem opening the file"; exit; } if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file"; exit; } echo "Thank you!"; fclose($handle);}else{echo "The file is not writable";}[/code]But this time I got 2 errors, the old one and error for the chmod() function too:[code]Warning: chmod(): Permission denied in C:\Inetpub\vhosts\oriosriddle.com\httpdocs\save.php on line 5Warning: fopen(46.txt): failed to open stream: Permission denied in C:\Inetpub\vhosts\oriosriddle.com\httpdocs\save.php on line 9[/code]Is it the host?Thanks again,Orio. Quote Link to comment https://forums.phpfreaks.com/topic/7308-fwrite/#findComment-27263 Share on other sites More sharing options...
wildteen88 Posted April 15, 2006 Share Posted April 15, 2006 0644 only allows to read the file. You cannot edit the file with that CHMOD value. To be able to edit a file you'll need to give the file a CHMOD value of 0777.Now I don't think chnaging the permissions of the file 0777 will affect the file much as you are on Windows using IIS. Windows doesn't have CHMOD. Only *unix and Macs have CHMOD. So I'd strip out your chmod function as it isn't going to do anything.My guess is that the file you are trying to edit is read-only (this you can check in your FTP Client by right clicking 46.txt and selecting properties and making sure the Read-only checkbox is unticked) or your webhost may be disabling the use of fopen. Quote Link to comment https://forums.phpfreaks.com/topic/7308-fwrite/#findComment-27264 Share on other sites More sharing options...
Orio Posted April 15, 2006 Author Share Posted April 15, 2006 I checked on my FTP the premission of the file, and in the place where the "Read-Only" check box is supposed to be there's this message:"This server does not support changing file premissions".Does this mean its a read only and I cant change it? But hows that possible if the is_writable() function didn't return FALSE?Orio. Quote Link to comment https://forums.phpfreaks.com/topic/7308-fwrite/#findComment-27268 Share on other sites More sharing options...
Orio Posted April 16, 2006 Author Share Posted April 16, 2006 *bump*Anyone?Orio. Quote Link to comment https://forums.phpfreaks.com/topic/7308-fwrite/#findComment-27488 Share on other sites More sharing options...
cwncool Posted April 16, 2006 Share Posted April 16, 2006 This means that your webserver wont let [i]you[/i] change the permissions. They can change them. Try emailing your webhost and ask them to change the permissions on 46.txt to 777 . Quote Link to comment https://forums.phpfreaks.com/topic/7308-fwrite/#findComment-27511 Share on other sites More sharing options...
Orio Posted April 16, 2006 Author Share Posted April 16, 2006 Thanks alot to everyone :)Orio. Quote Link to comment https://forums.phpfreaks.com/topic/7308-fwrite/#findComment-27530 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.