Page 1 of 1

Creat page from template using form

Posted: Tue Mar 25, 2008 7:32 pm
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.

Re: Creat page from template using form

Posted: Tue Mar 25, 2008 7:40 pm
by micknc
Sounds like the directory doesn't have the proper permissions to me.

Try setting the chmod to read/write to the directory.

Re: Creat page from template using form

Posted: Tue Mar 25, 2008 7:52 pm
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?

Re: Creat page from template using form

Posted: Tue Mar 25, 2008 8:04 pm
by micknc
If test.php is in the main directory then this should work:

$copyTo = $pagename . ".php";

Re: Creat page from template using form

Posted: Tue Mar 25, 2008 8:33 pm
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.

Re: Creat page from template using form

Posted: Tue Mar 25, 2008 8:44 pm
by micknc
To go to a sub directory I think you would use:

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

Re: Creat page from template using form

Posted: Tue Mar 25, 2008 9:29 pm
by zepher2
Thank you - it is working with the new subdirectory.