ameriblog Posted August 28, 2007 Share Posted August 28, 2007 I have this code: $file= fopen('wvhs_gm.txt' , 'w'); What I'd like to do is actually open the file based on the year in the address, so if the page is index.php?year=2007 it should open and write to the file 2007wvhs_gm.txt Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/66980-get-and-use-in-fopen/ Share on other sites More sharing options...
pocobueno1388 Posted August 28, 2007 Share Posted August 28, 2007 <?php if (isset($_GET['year'])){ $year = $_GET['year']; $open = $year.'wvhs_gm.txt'; } else { $open = "wvhs_gm.txt"; } $file= fopen($open , 'w'); ?> Give that a try. Quote Link to comment https://forums.phpfreaks.com/topic/66980-get-and-use-in-fopen/#findComment-335906 Share on other sites More sharing options...
eronmezza Posted August 28, 2007 Share Posted August 28, 2007 im not an expert but look around implode-explode where the first parameter is '='. so what i mean is that you put an implode on the url and implode makes out two part of the url, on before the '=' and one after (and this is gonna be the year.) make it a var like $year or anything. than make another var like $filename that is build up from $year + 'wvhs_gm.txt'. then comes the last var like $fileopen where you open the file like fopen ($filename, 'w') hope you get it, here's a manual for implode: http://www.tizag.com/phpT/php-string-implode.php Quote Link to comment https://forums.phpfreaks.com/topic/66980-get-and-use-in-fopen/#findComment-336001 Share on other sites More sharing options...
Wuhtzu Posted August 28, 2007 Share Posted August 28, 2007 Stick with $_GET['year'], it is the correct method. Quote Link to comment https://forums.phpfreaks.com/topic/66980-get-and-use-in-fopen/#findComment-336002 Share on other sites More sharing options...
ReDucTor Posted August 28, 2007 Share Posted August 28, 2007 <?php if (is_numeric($_GET['year']) && file_exists(intval($_GET['year']).'wvhs_gm.txt')){ $open = intval($year).'wvhs_gm.txt'; } else { $open = "wvhs_gm.txt"; } $file= fopen($open , 'w'); ?> SECURITY! Quote Link to comment https://forums.phpfreaks.com/topic/66980-get-and-use-in-fopen/#findComment-336005 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.