kidinbed Posted February 20, 2011 Share Posted February 20, 2011 I'm trying to create a an admin backend page for a food truck website. They need to be able to update their menu on the page pretty frequently, so I created a page that would use file_put_contents() to replace the text in an html file that I would display on the page in iframes, this would be the menu text. I have everything coded and working except file_put_contents() will not work at all. I'm using Go Daddy hosting, and they said that I could create an .ini file turning whatever setting it is that controls file_put_contents(), but I have tried numerous setting and can't get anywhere. This is the php code I'm working with: <?php $menu_text = $_POST['updateleft']; $html_begin = "<html><body><table bgcolor='black'><td><tr><font size='5' color='yellow'>"; $html_end = "</font></tr></td></table></body></table></html>"; $final_page = $html_begin.$menu_text.$html_end; $file_name = 'menuleft.html'; file_put_contents($final_page,$file_name); header("location:http://www.timbertheband.com/menu/menuadmin.html"); ?> and this is the admin page, not working: http://www.timbertheband.com/menu/menuadmin.html I'm not married to file_put_contents() or even this method so any suggestions at all I'm open to hearing. I've been working on this problem over a month now and I really need to get it figured out. The idea is I just need to have a way for them to update their menu and I don't want to create a database or anything, just keep it as simple as possible. Quote Link to comment https://forums.phpfreaks.com/topic/228293-file_put_contents-problems/ Share on other sites More sharing options...
BlueSkyIS Posted February 20, 2011 Share Posted February 20, 2011 not creating a database makes things much more difficult. if you stored the information in a database you wouldn't have to write an HTML file at all. you could just have PHP display the contents of the database. if you are married to not using a database, perhaps you should try fopen() and fwrite(). Quote Link to comment https://forums.phpfreaks.com/topic/228293-file_put_contents-problems/#findComment-1177207 Share on other sites More sharing options...
PFMaBiSmAd Posted February 20, 2011 Share Posted February 20, 2011 There is no php.ini setting that controls file_put_contents. What php errors do you get that would be telling you why the statement is failing? Since you are redirecting on the page, if output buffering is on, you won't see any php generated errors anyway. I recommend commenting out the header() redirect until you get the code on the page to work. Quote Link to comment https://forums.phpfreaks.com/topic/228293-file_put_contents-problems/#findComment-1177210 Share on other sites More sharing options...
kidinbed Posted February 20, 2011 Author Share Posted February 20, 2011 I'm trying to keep the site small and simple, and there is no need to store the old menus because it's always different. Can you give me any suggestions of how to incorporate fopen() and fwrite() into the code I've posted? Quote Link to comment https://forums.phpfreaks.com/topic/228293-file_put_contents-problems/#findComment-1177212 Share on other sites More sharing options...
BlueSkyIS Posted February 20, 2011 Share Posted February 20, 2011 I'm trying to keep the site small and simple, and there is no need to store the old menus because it's always different. Using a database doesn't necessarily mean storing historic data, but whatever you think is easier....... Here is a tutorial on writing content to file: http://www.tizag.com/phpT/filewrite.php Quote Link to comment https://forums.phpfreaks.com/topic/228293-file_put_contents-problems/#findComment-1177214 Share on other sites More sharing options...
kidinbed Posted February 20, 2011 Author Share Posted February 20, 2011 What php errors do you get that would be telling you why the statement is failing? Since you are redirecting on the page, if output buffering is on, you won't see any php generated errors anyway. I recommend commenting out the header() redirect until you get the code on the page to work. I've isolated the issue to be file_put_contents(). Here is the error I got when I tried your suggestion. Warning: file_put_contents(<html><body><table bgcolor='black'><td><tr><font size='5' color='yellow'>asdf</font></tr></td></table></body></table></html>) [function.file-put-contents]: failed to open stream: Invalid argument in D:\Hosting\7317202\html\menu\menuleft.php on line 10 Quote Link to comment https://forums.phpfreaks.com/topic/228293-file_put_contents-problems/#findComment-1177215 Share on other sites More sharing options...
Pikachu2000 Posted February 20, 2011 Share Posted February 20, 2011 You have the arguments reversed. The filename comes first. Quote Link to comment https://forums.phpfreaks.com/topic/228293-file_put_contents-problems/#findComment-1177217 Share on other sites More sharing options...
kidinbed Posted February 20, 2011 Author Share Posted February 20, 2011 I'm trying to keep the site small and simple, and there is no need to store the old menus because it's always different. Using a database doesn't necessarily mean storing historic data, but whatever you think is easier....... Here is a tutorial on writing content to file: http://www.tizag.com/phpT/filewrite.php I modified my code to your suggestion using fopen() and fwrite() <?php $myFile = "menuright.html"; $fh = fopen($myFile, 'w') or die("can't open file"); $html_begin = "<html><body><table bgcolor='black'><td><tr><font size='5' color='yellow'>"; $html_end = "</font></tr></td></table></body></table></html>"; $menu_text = $_POST['updateright']; $stringData = $html_begin.$menu_text.$html_end; fwrite($fh, $stringData); fclose($fh); ?> Now I'm getting a permissions error: Warning: fopen(menuright.html) [function.fopen]: failed to open stream: Permission denied in D:\Hosting\7317202\html\menu\menuleft.php on line 3 can't open file according to my phpinfo page allow_url_fopen is set to on, so I have no idea why it wouldn't work. Quote Link to comment https://forums.phpfreaks.com/topic/228293-file_put_contents-problems/#findComment-1177219 Share on other sites More sharing options...
BlueSkyIS Posted February 20, 2011 Share Posted February 20, 2011 that means permissions are wrong on the file menuright.html and it's not writable. you'll need to set that file to writable to write to it. that's chmod command in non-Windows, but I don't know what it is in Windows. I'm sure someone else here knows. Quote Link to comment https://forums.phpfreaks.com/topic/228293-file_put_contents-problems/#findComment-1177224 Share on other sites More sharing options...
kidinbed Posted February 20, 2011 Author Share Posted February 20, 2011 I checked the file permissions, I'm using filezilla and just had to write click the file to get to the permissions menu. All permissions are set, read, write, execute for all type of users. I'm stumped Quote Link to comment https://forums.phpfreaks.com/topic/228293-file_put_contents-problems/#findComment-1177229 Share on other sites More sharing options...
BlueSkyIS Posted February 20, 2011 Share Posted February 20, 2011 try using the full path to the file instead of just the file name. for instance: $myFile = "D:\Hosting\7317202\html\menu\menuright.html"; Quote Link to comment https://forums.phpfreaks.com/topic/228293-file_put_contents-problems/#findComment-1177230 Share on other sites More sharing options...
PFMaBiSmAd Posted February 20, 2011 Share Posted February 20, 2011 according to my phpinfo page allow_url_fopen is set to on ^^^ You are not using a URL (unless you altered the code you posted to hide what you are really doing), so that setting has noting to do with the problem. Quote Link to comment https://forums.phpfreaks.com/topic/228293-file_put_contents-problems/#findComment-1177232 Share on other sites More sharing options...
kidinbed Posted February 20, 2011 Author Share Posted February 20, 2011 You have the arguments reversed. The filename comes first. I changed that and I'm still getting the permissions error Warning: file_put_contents(menuright.html) [function.file-put-contents]: failed to open stream: Permission denied in D:\Hosting\7317202\html\menu\menuright.php on line 9 Quote Link to comment https://forums.phpfreaks.com/topic/228293-file_put_contents-problems/#findComment-1177233 Share on other sites More sharing options...
kidinbed Posted February 20, 2011 Author Share Posted February 20, 2011 try using the full path to the file instead of just the file name. for instance: $myFile = "D:\Hosting\7317202\html\menu\menuright.html"; Tried this, and had no effect, same error message as before Warning: fopen(menuleft.html) [function.fopen]: failed to open stream: Permission denied in D:\Hosting\7317202\html\menu\menuleft.php on line 3 Warning: file_put_contents(D:\Hosting\7317202\html\menu\menuright.html) [function.file-put-contents]: failed to open stream: Permission denied in D:\Hosting\7317202\html\menu\menuright.php on line 9 can't open file Quote Link to comment https://forums.phpfreaks.com/topic/228293-file_put_contents-problems/#findComment-1177234 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.