Creat page from template using form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zepher2
Forum Newbie
Posts: 5
Joined: Tue Mar 25, 2008 7:10 pm

Creat page from template using form

Post by zepher2 »

I am fairly new to PHP prgramming. I want to be able to create a new page on my website using a template and a form. I tried to adapt code from another thread for my prpose, but cannot get it to work. The form seems to work fine, but the Program returns the following error message when the form calls it:

Warning: Unable to create '/templatetest1.php': Permission denied in /home/a/a/aarda.org/html/test.php on line 14
IT HASN'T WORKED!


the program code is below:


<?php
$pagename = $_POST["pagename"]; // gets the form variable if globals are on or off

$copyFrom = "templates/pagetemplate.php";
$copyTo = "/" . $pagename . ".php";
$hasItWorked = copy($copyFrom, $copyTo);

if($hasItWorked) echo "IT HAS WORKED!";
if(!$hasItWorked) echo "IT HASN'T WORKED!";
?>


Thanks for any help you can give me.
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Re: Creat page from template using form

Post by micknc »

Sounds like the directory doesn't have the proper permissions to me.

Try setting the chmod to read/write to the directory.
zepher2
Forum Newbie
Posts: 5
Joined: Tue Mar 25, 2008 7:10 pm

Re: Creat page from template using form

Post by zepher2 »

I did change the directory permissions to read, write and execute or 667 but get the same error message. This is suppossed to go to the main directory, do I have the path right?
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Re: Creat page from template using form

Post by micknc »

If test.php is in the main directory then this should work:

$copyTo = $pagename . ".php";
zepher2
Forum Newbie
Posts: 5
Joined: Tue Mar 25, 2008 7:10 pm

Re: Creat page from template using form

Post by zepher2 »

I think my server does not permit changing file permissions of the main directory. I have created a subdirectory called events and given it file permissions of read write or 666. I do not know exactly how to code this new directory in the line;

$copyTo = "/" . $pagename . ".php";

I would like to try and see if the prgram works if I am putting the file in this sub directory.

Thanks for your help.
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Re: Creat page from template using form

Post by micknc »

To go to a sub directory I think you would use:

$copyTo = "new_dir/" . $pagename . ".php";
zepher2
Forum Newbie
Posts: 5
Joined: Tue Mar 25, 2008 7:10 pm

Re: Creat page from template using form

Post by zepher2 »

Thank you - it is working with the new subdirectory.
Post Reply