Ross2452 Posted July 28, 2010 Share Posted July 28, 2010 Hey guys, Im new to php and am having some trouble. Im sure im doing something silly, but after hunting the web for answers im still clueless. Basically I have a dropdown box that chooses a text file, then that file is loaded into a text area for editing. after editing, you click submit and it should save. the only problem is that fopen isnt getting the $page variable (works if i use a absolute path such as ../include/details1.txt) therefore giving me the error: Warning: fopen(../include/) [function.fopen]: failed to open stream: Is a directory in /home/*path removed*/admintest.php on line 55 Heres the code. Like i said, im very new to php so any advide would be great! Thanks guys! <?php $Desc1 = ($_POST['Desc1']); $Desc = addslashes($Desc1); $thisdir = getcwd(); $page = ($_GET['page']); if (!isset($_POST['submit' ])) { // if page is not submitted to itself echo the form ?> <html> <head> <script language="JavaScript" type="text/javascript" src="texteditor/wysiwyg.js"></script> <style type="text/css"> <!-- .smalltxt { font-size: 12px; } --> </style> </head> <body> <form name="FormName" action="<?php echo $PHP_SELF;?>" method="GET"> <select name="page" OnChange="document.FormName.submit();"> <option value="">Chooose Page...</option> <option value="details1.txt">1</option> <option value="details2.txt">2</option> <option value="details3.txt">3</option> </select> </form> <form method="POST" action="<?php echo $PHP_SELF;?>"> <textarea name="Desc1" id="Desc1" cols="65" rows="20"><?php include("../include/$page"); ?></textarea> <script language="JavaScript"> generate_wysiwyg('Desc1'); </script> <input type="submit" value="submit" name="submit"> </form> <?php } else { $myFile = "../include/$page"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "$Desc"; fwrite($fh, $stringData); fclose($fh); echo "Page Updated!"; } ?> Link to comment https://forums.phpfreaks.com/topic/209058-fopen-variable-filename-issue/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.