denoteone Posted March 6, 2008 Share Posted March 6, 2008 I am having issues with combining the file name and path to were it should be created. I beleive I should be doing this when i set the file handle. can anybody take a look at my code and let me know if I am on the right track with this..... <?php if(isset('submit')) { $filename = $_POST['file']; $titlename = $_POST['title']; $include = $_POST['text']; $path = "./content/"; $body = ' <html> <head> <title>'.$titlename.'</title> </head> <body bgcolor="blue"> <p>this is the page I created</p> <!--#include file="'.$include.'"--> </body> </html>' fh = fopen($path + $filename , "w")or die("can't open file");; fwrite($fh,$body); fclose($fh); }else{ ?> <html> <head> <title>Page Create</title> </head> <body> <form action="<?=$PHP_SELF?>" method="post"> <b>File Name:</b><input type="text" name="file" size="15"><br/> <b>Title of Page:</b><input type="text" name="title" size="15"></form><br/> <b>name of Included File:</b><input type="text" name="text" size="15"><br/> <input type="submit" value="submit" name="submit"> </body> </html> <?PHP } ?> I need the file path to go up on level and then into the content folder. Link to comment https://forums.phpfreaks.com/topic/94714-page-create-with-fopen/ Share on other sites More sharing options...
Neptunus Maris Posted March 6, 2008 Share Posted March 6, 2008 fh = fopen($path + $filename , "w")or die("can't open file");; CHANGE to THIS: fh = fopen($path.$filename , "w")or die("can't open file"); (This is not JavaScript where you concat with "+" ...go with this "." Link to comment https://forums.phpfreaks.com/topic/94714-page-create-with-fopen/#findComment-484885 Share on other sites More sharing options...
Neptunus Maris Posted March 6, 2008 Share Posted March 6, 2008 wait a minute... ALSO PUT "$" before you variable names like change fh ...to $fh SO $fh = fopen($path.$filename , "w") or die("can't open file"); Link to comment https://forums.phpfreaks.com/topic/94714-page-create-with-fopen/#findComment-484889 Share on other sites More sharing options...
denoteone Posted March 6, 2008 Author Share Posted March 6, 2008 ok here is my new code to create the page. I am not getting any error messages but the page is not being created in the content folder.... <?php if(isset($_POST["submit"])) { $filename = $_POST['file']; $titlename = $_POST['title']; $include = $_POST['text']; $path = "./content/"; $body = ' <html> <head> <title>'.$titlename.'</title> </head> <body bgcolor="blue"> <p>this is the page I created</p> <!--#include file="'.$include.'"--> </body> </html>'; $fh = fopen($path.$filename , "w") or die("can't open file"); fwrite($fh,$body); fclose($fh); }else{ ?> <html> <head> <title>Page Create</title> </head> <body> <form action="<?=$PHP_SELF?>" method="post"> <b>File Name:</b><input type="text" name="file" size="15"><br/> <b>Title of Page:</b><input type="text" name="title" size="15"></form><br/> <b>name of Included File:</b><input type="text" name="text" size="15"><br/> <input type="submit" value="submit" name="submit"> </body> </html> <?PHP } ?> Link to comment https://forums.phpfreaks.com/topic/94714-page-create-with-fopen/#findComment-485071 Share on other sites More sharing options...
denoteone Posted March 6, 2008 Author Share Posted March 6, 2008 I put an echo in my if statement to make sure that the script was getting that far and it did not work....does anybody see why the Submit button is not working/ Link to comment https://forums.phpfreaks.com/topic/94714-page-create-with-fopen/#findComment-485441 Share on other sites More sharing options...
trq Posted March 6, 2008 Share Posted March 6, 2008 You have no closing </form> html tag. Link to comment https://forums.phpfreaks.com/topic/94714-page-create-with-fopen/#findComment-485443 Share on other sites More sharing options...
denoteone Posted March 6, 2008 Author Share Posted March 6, 2008 Thanks! its been a long day.....(poor excuse) Link to comment https://forums.phpfreaks.com/topic/94714-page-create-with-fopen/#findComment-485448 Share on other sites More sharing options...
denoteone Posted March 7, 2008 Author Share Posted March 7, 2008 so I fixed the form closing tag and here is my new code still nothing.... <?php if(isset($_POST['submit'])) { $filename = $_POST['file']; $titlename = $_POST['title']; $include = $_POST['text']; $path = "./content/"; $body = ' <html> <head> <title>'.$titlename.'</title> </head> <body bgcolor="blue"> <p>this is the page I created</p> <!--#include file="'.$include.'"--> </body> </html>'; $fh = fopen($path.$filename , "w") or die("can't open file"); fwrite($fh,$body); fclose($fh); echo "it worked"; }else{ ?> <html> <head> <title>Page Create</title> </head> <body> <form action="<?=$PHP_SELF?>" method="post"> <b>File Name:</b><input type="text" name="file" size="15"><br/> <b>Title of Page:</b><input type="text" name="title" size="15"></form><br/> <b>name of Included File:</b><input type="text" name="text" size="15"><br/> <input type="submit" value="submit" name="submit"> </form> </body> </html> <?PHP } ?> Link to comment https://forums.phpfreaks.com/topic/94714-page-create-with-fopen/#findComment-486154 Share on other sites More sharing options...
denoteone Posted March 7, 2008 Author Share Posted March 7, 2008 got it. did not have the public set to write. Link to comment https://forums.phpfreaks.com/topic/94714-page-create-with-fopen/#findComment-486164 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.