Jump to content

Page Create with fopen


denoteone

Recommended Posts

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

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
}
?>

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
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.