thetwig Posted January 7, 2011 Share Posted January 7, 2011 Hi guys, I'm doing a website for the condo and I'm having troubles with the new year party registration form. I think it's got something to do with my file handling. When I run it on my wamp server, it works fine. But when I upload it onto the internet it gives me a whole bunch of warnings: Warning: fopen(newYearParty.txt) [function.fopen]: failed to open stream: Permission denied in /www/zymichost.com/i/n/d/inderasubangcondo/htdocs/newYrRegTq.php on line 18 Warning: fgets(): supplied argument is not a valid stream resource in /www/zymichost.com/i/n/d/inderasubangcondo/htdocs/newYrRegTq.php on line 19 Warning: fgets(): supplied argument is not a valid stream resource in /www/zymichost.com/i/n/d/inderasubangcondo/htdocs/newYrRegTq.php on line 20 Heres my code: <?php $nam = $_POST["nam"]; $block = $_POST["block"]; $floor = $_POST["floor"]; $house = $_POST["house"]; $adults = $_POST["adults"]; $children = $_POST["children"]; $guests = $_POST["guests"]; $nam = $_POST["nam"]; global $fn, $ft; //set id and update total numbers $fn = fopen("newYearParty.txt","a+"); $line1 = fgets($fn); $arr1 = explode(": ", $line1); //adults $line2 = fgets($fn); $arr2 = explode(": ", $line2); //children $line3 = fgets($fn); $arr3 = explode(": ", $line3); //guests $line4 = fgets($fn); $arr4 = explode(": ", $line4); //total $line4 = fgets($fn); //blank line $numAdults = $arr1[1]+$adults; $numChildren = $arr2[1]+$children; $numGuests = $arr3[1]+$guests; $numTotal = $numAdults+$numChildren+$numGuests; $id = "nothing"; while(!feof($fn)) { $line = fgets($fn); //id $arr = explode(": ", $line); $id = $arr[1] + 1; //get latest id and add 1 to it for($i=0; $i<6; $i++) { $line = fgets($fn); } } fclose($fn); if($id == "nothing") { $id = "0"; } //end of set id //write to file $line0 = "\r\nId: ".$id."\r\n"; $line1 = "Name: ".$nam."\r\n"; $line2 = "Unit: ".$block."-".$floor."-".$house."\r\n"; $line3 = "Adults: ".$adults."\r\n"; $line4 = "Children: ".$children."\r\n"; $line5 = "Guests: ".$guests."\r\n"; $fn = fopen("newYearParty.txt","a+"); fwrite($fn, $line0); fwrite($fn, $line1); fwrite($fn, $line2); fwrite($fn, $line3); fwrite($fn, $line4); fwrite($fn, $line5); fclose($fn); //end of write to file //write new numbers to file $ft = fopen("newYearPartyTemp.txt","a+"); $lineA = "Adults: ".$numAdults."\r\n"; $lineC = "Children: ".$numChildren."\r\n"; $lineG = "Guests: ".$numGuests."\r\n"; $lineT = "Total: ".$numTotal."\r\n\r\n"; fwrite($ft, $lineA); fwrite($ft, $lineC); fwrite($ft, $lineG); fwrite($ft, $lineT); $fn = fopen("newYearParty.txt","a+"); for($i=0; $i<5; $i++) { $line = fgets($fn); } while(!feof($fn)) { $line = fgets($fn); fwrite($ft, $line); } fclose($fn); fclose($ft); unlink("newYearParty.txt"); //delete newYearParty.txt rename("newYearPartyTemp.txt","newYearParty.txt"); //rename newYearPartyTemp.txt to newYearParty.txt //end of write new numbers to file ?> Any ideas on how to fix this up? Thanks a lot in advance. Quote Link to comment https://forums.phpfreaks.com/topic/223646-warning-fgets-supplied-argument-is-not-a-valid-stream-resource/ Share on other sites More sharing options...
trq Posted January 7, 2011 Share Posted January 7, 2011 This part says it all.... failed to open stream: Permission denied You do not have permission to write to that directory. Quote Link to comment https://forums.phpfreaks.com/topic/223646-warning-fgets-supplied-argument-is-not-a-valid-stream-resource/#findComment-1156103 Share on other sites More sharing options...
thetwig Posted January 7, 2011 Author Share Posted January 7, 2011 So is there any way I can get permission? And why do I need permission to write to a file? Thanks a heap. Quote Link to comment https://forums.phpfreaks.com/topic/223646-warning-fgets-supplied-argument-is-not-a-valid-stream-resource/#findComment-1156106 Share on other sites More sharing options...
Zurev Posted January 7, 2011 Share Posted January 7, 2011 And why do I need permission to write to a file? Srsly? So is there any way I can get permission? CHMOD your file to 755, if that doesn't work then 777 will. Explained in more detail here: http://www.pageresource.com/cgirec/chmod.htm On a side note, while databases can be daunting at first, I think it may be much more suitable for your situation. Have you considered implementing a database rather than using a text file for all of it? Quote Link to comment https://forums.phpfreaks.com/topic/223646-warning-fgets-supplied-argument-is-not-a-valid-stream-resource/#findComment-1156111 Share on other sites More sharing options...
thetwig Posted January 8, 2011 Author Share Posted January 8, 2011 hey Zurev.. I came up with this error: Parse error: syntax error, unexpected T_LNUMBER in /www/zymichost.com/i/n/d/inderasubangcondo/htdocs/newYrRegTq.php on line 14 I tried putting that line in, and since I don't really understand it I tried 4 combinations of what I thought it could be changing the .cgi to .txt and the 755 to 777.. 1. Telnet/cgi-bin>chmod 755 newYearParty.cgi 2. Telnet/cgi-bin>chmod 777 newYearParty.cgi 3. Telnet/cgi-bin>chmod 755 newYearParty.txt 4. Telnet/cgi-bin>chmod 777 newYearParty.txt All four didn't work... here's where i put it.. (line 14) <?php $nam = $_POST["nam"]; $block = $_POST["block"]; $floor = $_POST["floor"]; $house = $_POST["house"]; $adults = $_POST["adults"]; $children = $_POST["children"]; $guests = $_POST["guests"]; Telnet/cgi-bin>chmod 777 newYearParty.cgi //I PUT IT HERE //set id and update total numbers $fn = fopen("newYearParty.txt","a+"); $line1 = fgets($fn); $arr1 = explode(": ", $line1); //adults $line2 = fgets($fn); $arr2 = explode(": ", $line2); //children $line3 = fgets($fn); $arr3 = explode(": ", $line3); //guests $line4 = fgets($fn); $arr4 = explode(": ", $line4); //total $line4 = fgets($fn); //blank line $numAdults = $arr1[1]+$adults; $numChildren = $arr2[1]+$children; $numGuests = $arr3[1]+$guests; $numTotal = $numAdults+$numChildren+$numGuests; $id = "nothing"; while(!feof($fn)) { $line = fgets($fn); //id $arr = explode(": ", $line); $id = $arr[1] + 1; //get latest id and add 1 to it for($i=0; $i<6; $i++) { $line = fgets($fn); } } fclose($fn); if($id == "nothing") { $id = "0"; } //end of set id //write to file $line0 = "\r\nId: ".$id."\r\n"; $line1 = "Name: ".$nam."\r\n"; $line2 = "Unit: ".$block."-".$floor."-".$house."\r\n"; $line3 = "Adults: ".$adults."\r\n"; $line4 = "Children: ".$children."\r\n"; $line5 = "Guests: ".$guests."\r\n"; $fn = fopen("newYearParty.txt","a+"); fwrite($fn, $line0); fwrite($fn, $line1); fwrite($fn, $line2); fwrite($fn, $line3); fwrite($fn, $line4); fwrite($fn, $line5); fclose($fn); //end of write to file //write new numbers to file $ft = fopen("newYearPartyTemp.txt","a+"); $lineA = "Adults: ".$numAdults."\r\n"; $lineC = "Children: ".$numChildren."\r\n"; $lineG = "Guests: ".$numGuests."\r\n"; $lineT = "Total: ".$numTotal."\r\n\r\n"; fwrite($ft, $lineA); fwrite($ft, $lineC); fwrite($ft, $lineG); fwrite($ft, $lineT); $fn = fopen("newYearParty.txt","a+"); for($i=0; $i<5; $i++) { $line = fgets($fn); } while(!feof($fn)) { $line = fgets($fn); fwrite($ft, $line); } fclose($fn); fclose($ft); unlink("newYearParty.txt"); //delete newYearParty.txt rename("newYearPartyTemp.txt","newYearParty.txt"); //rename newYearPartyTemp.txt to newYearParty.txt //end of write new numbers to file ?> Let me know what I'm doing wrong. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/223646-warning-fgets-supplied-argument-is-not-a-valid-stream-resource/#findComment-1156543 Share on other sites More sharing options...
Zurev Posted January 8, 2011 Share Posted January 8, 2011 hey Zurev.. I came up with this error: Parse error: syntax error, unexpected T_LNUMBER in /www/zymichost.com/i/n/d/inderasubangcondo/htdocs/newYrRegTq.php on line 14 I tried putting that line in, and since I don't really understand it I tried 4 combinations of what I thought it could be changing the .cgi to .txt and the 755 to 777.. 1. Telnet/cgi-bin>chmod 755 newYearParty.cgi 2. Telnet/cgi-bin>chmod 777 newYearParty.cgi 3. Telnet/cgi-bin>chmod 755 newYearParty.txt 4. Telnet/cgi-bin>chmod 777 newYearParty.txt All four didn't work... here's where i put it.. (line 14) <?php $nam = $_POST["nam"]; $block = $_POST["block"]; $floor = $_POST["floor"]; $house = $_POST["house"]; $adults = $_POST["adults"]; $children = $_POST["children"]; $guests = $_POST["guests"]; Telnet/cgi-bin>chmod 777 newYearParty.cgi //I PUT IT HERE //set id and update total numbers $fn = fopen("newYearParty.txt","a+"); $line1 = fgets($fn); $arr1 = explode(": ", $line1); //adults $line2 = fgets($fn); $arr2 = explode(": ", $line2); //children $line3 = fgets($fn); $arr3 = explode(": ", $line3); //guests $line4 = fgets($fn); $arr4 = explode(": ", $line4); //total $line4 = fgets($fn); //blank line $numAdults = $arr1[1]+$adults; $numChildren = $arr2[1]+$children; $numGuests = $arr3[1]+$guests; $numTotal = $numAdults+$numChildren+$numGuests; $id = "nothing"; while(!feof($fn)) { $line = fgets($fn); //id $arr = explode(": ", $line); $id = $arr[1] + 1; //get latest id and add 1 to it for($i=0; $i<6; $i++) { $line = fgets($fn); } } fclose($fn); if($id == "nothing") { $id = "0"; } //end of set id //write to file $line0 = "\r\nId: ".$id."\r\n"; $line1 = "Name: ".$nam."\r\n"; $line2 = "Unit: ".$block."-".$floor."-".$house."\r\n"; $line3 = "Adults: ".$adults."\r\n"; $line4 = "Children: ".$children."\r\n"; $line5 = "Guests: ".$guests."\r\n"; $fn = fopen("newYearParty.txt","a+"); fwrite($fn, $line0); fwrite($fn, $line1); fwrite($fn, $line2); fwrite($fn, $line3); fwrite($fn, $line4); fwrite($fn, $line5); fclose($fn); //end of write to file //write new numbers to file $ft = fopen("newYearPartyTemp.txt","a+"); $lineA = "Adults: ".$numAdults."\r\n"; $lineC = "Children: ".$numChildren."\r\n"; $lineG = "Guests: ".$numGuests."\r\n"; $lineT = "Total: ".$numTotal."\r\n\r\n"; fwrite($ft, $lineA); fwrite($ft, $lineC); fwrite($ft, $lineG); fwrite($ft, $lineT); $fn = fopen("newYearParty.txt","a+"); for($i=0; $i<5; $i++) { $line = fgets($fn); } while(!feof($fn)) { $line = fgets($fn); fwrite($ft, $line); } fclose($fn); fclose($ft); unlink("newYearParty.txt"); //delete newYearParty.txt rename("newYearPartyTemp.txt","newYearParty.txt"); //rename newYearPartyTemp.txt to newYearParty.txt //end of write new numbers to file ?> Let me know what I'm doing wrong. Thanks for your help. I'm afraid this is my fault, I meant to give you that page so you could understand the concept, that isn't a line meant for PHP, not in that context anyway. CHMOD by right clicking the file in your ftp client and see from there, it's changing the mode, however, an easier bet for you is to use php's chmod function. http://php.net/manual/en/function.chmod.php Quote Link to comment https://forums.phpfreaks.com/topic/223646-warning-fgets-supplied-argument-is-not-a-valid-stream-resource/#findComment-1156546 Share on other sites More sharing options...
thetwig Posted January 8, 2011 Author Share Posted January 8, 2011 DUDE!!! ZUREV! ur a freakin genius!... the coding didnt work... but i manually did it from my ftp.... it works fine now!!! WOO!! thnx a heap.... seriously man... appreciate it!! THANKS! Quote Link to comment https://forums.phpfreaks.com/topic/223646-warning-fgets-supplied-argument-is-not-a-valid-stream-resource/#findComment-1156562 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.