Page 1 of 2 12 LastLast
Results 1 to 16 of 17

Thread: Automatically Creating A New Page

  1. #1
    Hmmm bed
    Join Date
    Jul 2003
    Posts
    441
    Thanks
    5
    Thanked
    0 times in 0 posts

    Automatically Creating A New Page

    Ok, for the latest project I am undertaking, I need a feature where, when a user clicks a link a copy of a template file is copied, creating a whole new HTML file.

    Can anyone help me with a script to do this ie. when the script is run it copy's the template file to create a new file?

    it will be running on a linux server that can run cgi(perl,c,python)/php.

    cheers

    Basher

  2. #2
    Goat Boy
    Join Date
    Jul 2003
    Location
    Alexandra Park, London
    Posts
    2,428
    Thanks
    0
    Thanked
    0 times in 0 posts
    I'm not quite sure what you mean. Can you explain? What are you actually trying to achieve? Are you saying you want to write a generic page template that can have different content within it?
    "All our beliefs are being challenged now, and rightfully so, they're stupid." - Bill Hicks

  3. #3
    Hmmm bed
    Join Date
    Jul 2003
    Posts
    441
    Thanks
    5
    Thanked
    0 times in 0 posts
    no no, sorry a poor explanation .. so here goes .....

    I want a user to fill in a text field with a filename in it (eg NewPage.htm), when the user clicks submit, the script creates a new page that looks exactly like a pre defined template page.

    cheers

    Basher

  4. #4
    Goat Boy
    Join Date
    Jul 2003
    Location
    Alexandra Park, London
    Posts
    2,428
    Thanks
    0
    Thanked
    0 times in 0 posts
    Just use php. Create the file template, call it say

    template.php

    Then just use the file copy php directive...

    http://www.php.net/manual/en/function.copy.php

    When the user submits the form, just copy the template and use the user submitted field as the copy to name.
    "All our beliefs are being challenged now, and rightfully so, they're stupid." - Bill Hicks

  5. #5
    HEXUS.social member Agent's Avatar
    Join Date
    Jul 2003
    Location
    Internet
    Posts
    19,185
    Thanks
    739
    Thanked
    1,614 times in 1,050 posts
    But why would you want to do that in the first place ?

    Your just going to end up with the same file, duplicated a lot with a different filename
    Quote Originally Posted by Saracen View Post
    And by trying to force me to like small pants, they've alienated me.

  6. #6
    Paranoid??? Who Me???
    Join Date
    Jul 2003
    Location
    127.0.0.1
    Posts
    631
    Thanks
    1
    Thanked
    1 time in 1 post
    think the idea is gonna be more along the lines of the template would have standard includes for page layout with a dynamic content user entry bit... along the lines of a CMS... but not.. if you know what I mean...

    I did a similar thing in CF for my an intranet... where a user could update their area of the site, and add pages from a set template without bugging me... they had the ability to amend and add links to their front page as well...

  7. #7
    HEXUS.social member Agent's Avatar
    Join Date
    Jul 2003
    Location
    Internet
    Posts
    19,185
    Thanks
    739
    Thanked
    1,614 times in 1,050 posts
    Originally posted by kaillum
    I did a similar thing in CF for my an intranet... where a user could update their area of the site, and add pages from a set template without bugging me... they had the ability to amend and add links to their front page as well...
    But you could do that with just the template. You wouldnt need loads of seperate pages, just one for each design (you could acctually do it with less, but it gets complicated) and then call the information from a database (or file) for the page.
    Its fairly common in CMS systems, just use one template page, then you have a referer to each news story. Even HEXUS does it with "review.php?newsidhere".
    Quote Originally Posted by Saracen View Post
    And by trying to force me to like small pants, they've alienated me.

  8. #8
    Hmmm bed
    Join Date
    Jul 2003
    Posts
    441
    Thanks
    5
    Thanked
    0 times in 0 posts
    Originally posted by kaillum
    think the idea is gonna be more along the lines of the template would have standard includes for page layout with a dynamic content user entry bit... along the lines of a CMS... but not.. if you know what I mean...

    yup that's the idea,

    how would i let the user be able to decide teh actual filename of the new file?

    cheers,

    Basher
    Last edited by Basher; 27-08-2003 at 07:10 PM.

  9. #9
    Goat Boy
    Join Date
    Jul 2003
    Location
    Alexandra Park, London
    Posts
    2,428
    Thanks
    0
    Thanked
    0 times in 0 posts
    Why exactly do you want to do this?

    The way most sites work is by having one template. For example, lets call it "page.php" or whatever. There is only one copy of this template. The template contains all the navigation etc. etc. for the site, but the main content area is left blank, ready for content.

    You then make use of some sort of scripting to grab the content from somewhere and add it to your page. You can use server side includes to do this, or a scripting language like php, asp or jsp.

    Say for example you had three pages on your site. Homepage, About Me and Links. The homepage could be referenced by something like:

    page.php?page=homepage

    or

    page.php?page=aboutme

    etc. etc. It is then up to you to write the scripting to grab the appropriate piece of content and include it within the template.

    Is this what you want to achieve, or haev I got completely the wrong end of the stick?
    "All our beliefs are being challenged now, and rightfully so, they're stupid." - Bill Hicks

  10. #10
    Hmmm bed
    Join Date
    Jul 2003
    Posts
    441
    Thanks
    5
    Thanked
    0 times in 0 posts
    no not really what i want to achieve, im using html and a content management system which can update the html (page publisher its called from interactivetools.com). the problem is, this CMS can't add pages from a template, which is why i need this script, to create the pages so they can be used if the user wishes to add pages on diff subjects at a later date if u see what i mean.

    I havn't really used PHP before so wouldn't really have the experiance to do the whole PHP/ssi solution i dont think,
    thanks

    Basher

  11. #11
    HEXUS.social member Agent's Avatar
    Join Date
    Jul 2003
    Location
    Internet
    Posts
    19,185
    Thanks
    739
    Thanked
    1,614 times in 1,050 posts
    This is somthing i quickly nocked up using the function DaBeeeenster mentioned.
    If you dont understand any of it just ask
    Keep in mind the that the directory of the script needs to beable to be written to by all users, so CHMOD it for this (CHMOD all users to 7).
    I have also only done a small amount of error/report checking (where it reports if it was copied sucessfully or not). If the filename doesnt exist you will get the full PHP error and not a friendly scripted error. PHP errors are generaly friendly, aslong as its not involving loops.

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Agents file copy example</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?
    // if form has not not yet been submitted
    // display initial form to get filenames
    if (!$submit)
    {
    ?>
    <form name="form1" method="post" action="<? echo $PHP_SELF?>">
    <p>&nbsp;  </p>
    <table width="75%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="23%" height="24">Filename to be copied</td>
        <td width="77%"><input name="filename" type="text" id="filename"></td>
      </tr>
      <tr>
        <td>Destination Filename</td>
        <td><input name="destfilename" type="text" id="destfilename"></td>
      </tr>
    </table>
    <p>&nbsp;</p>
    <p>
      <input name="submit" type="hidden" id="submit2" value="true">
    </p>
    <p>
      <input type="submit" name="Submit" value="Submit">
    </p>
    </form>


    <?
    // if forum has been submitted, then do this...
    // the way the form knows if it has been submitted or not, is by checking the hidden value "submit" contained in the form.
    }
    else
    {
    if (!
    copy($filename$destfilename)) {
        print (
    "Couldnt not copy $filename.<br>\n");
        }
        else {
        print (
    "File $filename was sucessfully copied to $destfilename");
        }
    }
    ?>
    </body>
    </html>
    Copy and paste that into a new php file (you can name it anything, as ive used the "$PHP_SELF" variable, so it submits to itself). This way it doesnt matter what you call the file.
    You need to specify the extension of both the filenames. If you want it to do this automaticaly, this is only a few more lines.
    Its also HTML 4.01 transitional certified, so it should work in all browsers without a problem
    Quote Originally Posted by Saracen View Post
    And by trying to force me to like small pants, they've alienated me.

  12. #12
    Hmmm bed
    Join Date
    Jul 2003
    Posts
    441
    Thanks
    5
    Thanked
    0 times in 0 posts
    thats brill thanks, i'll give it a whirl later once ive eaten

    thanks

    Basher

  13. #13
    Hmmm bed
    Join Date
    Jul 2003
    Posts
    441
    Thanks
    5
    Thanked
    0 times in 0 posts
    Hi,, the script works great cheers m8, how would i go about say having the script in a directory, say www.mydomain.com/admin but when the file is copied, it get copied to the root (well public_html) of www.mydomain.com, how would i go about that?

    thanks for the help

  14. #14
    Hmmm bed
    Join Date
    Jul 2003
    Posts
    441
    Thanks
    5
    Thanked
    0 times in 0 posts
    sorry to be a pain but you said if i wished to set the filanames or extensions automatically it was only a few more lines of code, how would I do this?

    Cheers

    Basher

  15. #15
    HEXUS.social member Agent's Avatar
    Join Date
    Jul 2003
    Location
    Internet
    Posts
    19,185
    Thanks
    739
    Thanked
    1,614 times in 1,050 posts
    I added a variable to the script called $ext.
    Set this at the top of the page to what you want the file extension is. The script assumes that you want the same extension for the file as the orignal one.

    Also, to say to copy to the directory "up" from the one your currently in, you use ../
    As your files are probably "up" from your current directory, then in a folder called "public_html" this becomes "../public_html"
    IF it is different its very easy to change it, just look at the script
    You can also use absolute paths for it, so for example, if you were hosted on 34sp.com using "/usr/local/psa/home/vhosts/websitename.com/httpdocs/" would work fine

    So the script as it is :
    I have not had time to text this

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Agents file copy example</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?
    // CONFIGURATION
    // set the file extension for the file thats to be copied.
    $ext ".htm";

    // END CONFIGURATION

    // if form has not not yet been submitted
    // display initial form to get filenames
    if (!$submit)
    {
    ?>
    <form name="form1" method="post" action="<? echo $PHP_SELF?>">
    <p>&nbsp;  </p>
    <table width="75%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="23%" height="24">Filename to be copied</td>
        <td width="77%"><input name="filename" type="text" id="filename"></td>
      </tr>
      <tr>
        <td>Destination Filename</td>
        <td><input name="destfilename" type="text" id="destfilename"></td>
      </tr>
    </table>
    <p>&nbsp;</p>
    <p>
      <input name="submit" type="hidden" id="submit2" value="true">
    </p>
    <p>
      <input type="submit" name="Submit" value="Submit">
    </p>
    </form>


    <?
    // if forum has been submitted, then do this...
    // the way the form knows if it has been submitted or not, is by checking teh hidden value "submit" contained in the form.
    }
    else
    {
    if (!
    copy($filename.$ext, ../public_html/$destfilename.$ext)) {
        print (
    "Couldnt not copy $filename.$ext.<br>\n");
        }
        else {
        print (
    "File $filename.$ext was sucessfully copied to $destfilename.$ext");
        }
    }
    ?>
    </body>
    </html>
    There may be a stupid small mistake it in, if there is ill look into it later.
    Remember to make the directory where the files are going to be copied to a CHMOD of 7 for all users.
    Quote Originally Posted by Saracen View Post
    And by trying to force me to like small pants, they've alienated me.

  16. #16
    Hmmm bed
    Join Date
    Jul 2003
    Posts
    441
    Thanks
    5
    Thanked
    0 times in 0 posts
    thanky you, ill give it a go later when I get back home

    Thanks

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •