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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.