allex01 Posted February 18, 2008 Share Posted February 18, 2008 I have a file that contains all types of constants that looks like this $CFG['admin']['value']['article_value'] = '9'; $CFG['admin']['value']['article_upload_value'] = '10'; $CFG['admin']['value']['game_comment_value'] = '11'; I created a form with input fields where a user can input and change the values for article_value, article_upload_value, game_comment_value. My question is , how can i make those values replace the current values in the constant file when the submit button is hit. You don't have to work with my current scheme. A simple example on how to update constants in a file would be helpfull. Link to comment https://forums.phpfreaks.com/topic/91613-updating-constants-in-a-file/ Share on other sites More sharing options...
trq Posted February 18, 2008 Share Posted February 18, 2008 They are not constants, but simple array values. As for writting to a file, take a look at fwrite(). Link to comment https://forums.phpfreaks.com/topic/91613-updating-constants-in-a-file/#findComment-469248 Share on other sites More sharing options...
allex01 Posted February 18, 2008 Author Share Posted February 18, 2008 Yes you're write. How can i write to the array values using a form with input fields. I dont' get how to use fwrite to replace the value only. Link to comment https://forums.phpfreaks.com/topic/91613-updating-constants-in-a-file/#findComment-469249 Share on other sites More sharing options...
trq Posted February 18, 2008 Share Posted February 18, 2008 Do i still need to use fwrite() If you want to actually overwrite the values in the file. If you just want them temporarley overiden you would use something like.... <?php if (isset($_POST['submit'])) { $CFG['admin']['value']['article_value'] = $_POST['admin_value_article_value']; $CFG['admin']['value']['article_upload_value'] = $_POST['admin_value_article_upload_value']; $CFG['admin']['value']['game_comment_value'] = $_POST['admin_value_game_comment_value']; } ?> Link to comment https://forums.phpfreaks.com/topic/91613-updating-constants-in-a-file/#findComment-469250 Share on other sites More sharing options...
allex01 Posted February 18, 2008 Author Share Posted February 18, 2008 Thank you Thorpe. I was looking for a permanent overwrite and not temporary. Link to comment https://forums.phpfreaks.com/topic/91613-updating-constants-in-a-file/#findComment-469251 Share on other sites More sharing options...
allex01 Posted February 18, 2008 Author Share Posted February 18, 2008 On further support on this would be appreciated. I just need guidance in the right direction. Link to comment https://forums.phpfreaks.com/topic/91613-updating-constants-in-a-file/#findComment-469259 Share on other sites More sharing options...
trq Posted February 18, 2008 Share Posted February 18, 2008 Did you take a look at fwrite()? Link to comment https://forums.phpfreaks.com/topic/91613-updating-constants-in-a-file/#findComment-469269 Share on other sites More sharing options...
allex01 Posted February 18, 2008 Author Share Posted February 18, 2008 Sure, i did. fwrite() writes to a file but my question was how to make it write to a specific array value in the file mentioned above I'm assuming the general funcitonality of fwrite only writes at the end of a text file by default correct?.. Link to comment https://forums.phpfreaks.com/topic/91613-updating-constants-in-a-file/#findComment-469276 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.