Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php form to generate a html document

    is there anyway i can use a php form to be able to generate a html file depending on what you want to call the filename, and be able to write the code in below. it has to be placed in the same directory as where the php form is.

    <HTML>
    <HEAD>
    </HEAD>
    <BODY leftMargin=0 topMargin=0 link="#000080" vlink="#000080" alink="#000080" bgcolor="#CCFF99">
    <table border="1" cellpadding="0" cellspacing="0" width="100%" height="100%" bordercolor="#000000" bgcolor="#CCFF99">
    <tr>
    <td width="100%" valign="top">
    &nbsp;
    <div align="center">
    <table border="0" cellpadding="3" width="400" background="../topmenu.gif" height="30">
    <tr>
    <td>
    <p align="center"><font color="#FFFFFF" size="2" face="Arial"><b>General Pool</b></font></td>
    </tr>
    </table>
    </div>
    &nbsp;
    <div align="center">
    <TABLE cellSpacing=0 cellPadding=0 border=1 width="440" bordercolor="#555576">
    <TBODY>
    <tr>
    <TD bgColor=#000000 width="317">
    <p align="left"><font color="#ffffff" face="Verdana" size="1"><b>Post&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="postnewtopic1.htm"><img border="0" src="postnew.gif" width="86" height="19"></a></b></font></p>
    </TD>
    <TD bgColor=#000000 width="123">
    <p align="left"><font color="#ffffff" face="Verdana" size="1"><b>Poster</b></font></p>
    </TD>
    </tr>

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Of course you can. Is the form going to contain the contents for this new html file? What is the new file suppose to be called?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no the form will only contain the output filename of the html specified by the user.

    i want the php or cgi script to then write what is below after creating the blank document with the user specified filename:

    <HTML>
    <HEAD>
    </HEAD>
    <BODY leftMargin=0 topMargin=0 link="#000080" vlink="#000080" alink="#000080" bgcolor="#CCFF99">
    <table border="1" cellpadding="0" cellspacing="0" width="100%" height="100%" bordercolor="#000000" bgcolor="#CCFF99">
    <tr>
    <td width="100%" valign="top">

    <div align="center">
    <table border="0" cellpadding="3" width="400" background="../topmenu.gif" height="30">
    <tr>
    <td>
    <p align="center"><font color="#FFFFFF" size="2" face="Arial"><b>General Pool</b></font></td>
    </tr>
    </table>
    </div>

    <div align="center">
    <TABLE cellSpacing=0 cellPadding=0 border=1 width="440" bordercolor="#555576">
    <TBODY>
    <tr>
    <TD bgColor=#000000 width="317">
    <p align="left"><font color="#ffffff" face="Verdana" size="1"><b>Post
    <a href="postnewtopic1.htm"><img border="0" src="postnew.gif" width="86" height="19"></a></b></font></p>
    </TD>
    <TD bgColor=#000000 width="123">
    <p align="left"><font color="#ffffff" face="Verdana" size="1"><b>Poster</b></font></p>
    </TD>
    </tr>

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    You can do this several different ways. Here is one example:

    Create a php file that will actually create the html file:

    PHP Code:
    <?php 
    $file_name 
    $HTTP_POST_VARS["new_file"]; 

    $contents = <<<EOD


    <HTML> 
    <HEAD> 
    </HEAD> 
    <BODY leftMargin=0 topMargin=0 link="#000080" vlink="#000080" alink="#000080" bgcolor="#CCFF99"> 
    <table border="1" cellpadding="0" cellspacing="0" width="100%" height="100%" bordercolor="#000000" bgcolor="#CCFF99"> 
    <tr> 
    <td width="100%" valign="top"> 

    <div align="center"> 
    <table border="0" cellpadding="3" width="400" background="../topmenu.gif" height="30"> 
    <tr> 
    <td> 
    <p align="center"><font color="#FFFFFF" size="2" face="Arial"><b>General Pool</b></font></td> 
    </tr> 
    </table> 
    </div> 

    <div align="center"> 
    <TABLE cellSpacing=0 cellPadding=0 border=1 width="440" bordercolor="#555576"> 
    <TBODY> 
    <tr> 
    <TD bgColor=#000000 width="317"> 
    <p align="left"><font color="#ffffff" face="Verdana" size="1"><b>Post 
    <a href="postnewtopic1.htm"><img border="0" src="postnew.gif" width="86" height="19"></a></b></font></p> 
    </TD> 
    <TD bgColor=#000000 width="123"> 
    <p align="left"><font color="#ffffff" face="Verdana" size="1"><b>Poster</b></font></p> 
    </TD> 
    </tr>


    EOD;

    $file_pointer fopen($file_name"w"); 
    $lock flock($file_pointerLOCK_EX); 

    if (
    $lock){
     
    fputs($file_pointer$contents); 
     
    flock($file_pointerLOCK_UN); 

    fclose($file_pointer); 

    ?>
    and then your html form that will supply the file name:

    Code:
    <form name="form1" method="post" action="create_file.php">
      <input type="text" name="new_file">
      <br>
      <br>
      <input type="submit" name="Submit" value="Submit">
    </form>
    and that will simply create the file with that file name with the contents provided in the contents variable.

    Note that im using the herdoc syntax which I believe is supported only in php4+. Of course im assuming your host is using php4+ as they should be.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    New Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how do i then get the php script to go to the new file just created?


    ive also tried to chmod the file but permission is denied? is it already chmod to 777?
    Last edited by andrewsheldon98; 07-20-2002 at 08:52 PM.

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Ok I should have guessed you would ask that. Here is a way to redirect to their page:

    PHP Code:
    <?php
    $is_submitted 
    $HTTP_POST_VARS["submit"];
    $file_name $HTTP_POST_VARS["new_file"];

    if(!isset(
    $is_submitted)){
    ?>

    <html>
    <head>
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <form name="form1" method="post" action="<?php echo $PHP_SELF?>">
      <input type="text" name="new_file">
      <br>
      <br>
      <input type="submit" name="submit" value="Submit">
    </form>
    </body>
    </html>

    <?php 
    }
    else{

    $contents = <<<EOD

    <HTML> 
    <HEAD> 
    </HEAD> 
    <BODY leftMargin=0 topMargin=0 link="#000080" vlink="#000080" alink="#000080" bgcolor="#CCFF99"> 
    <table border="1" cellpadding="0" cellspacing="0" width="100%" height="100%" bordercolor="#000000" bgcolor="#CCFF99"> 
    <tr> 
    <td width="100%" valign="top"> 

    <div align="center"> 
    <table border="0" cellpadding="3" width="400" background="../topmenu.gif" height="30"> 
    <tr> 
    <td> 
    <p align="center"><font color="#FFFFFF" size="2" face="Arial"><b>General Pool</b></font></td> 
    </tr> 
    </table> 
    </div> 

    <div align="center"> 
    <TABLE cellSpacing=0 cellPadding=0 border=1 width="440" bordercolor="#555576"> 
    <TBODY> 
    <tr> 
    <TD bgColor=#000000 width="317"> 
    <p align="left"><font color="#ffffff" face="Verdana" size="1"><b>Post 
    <a href="postnewtopic1.htm"><img border="0" src="postnew.gif" width="86" height="19"></a></b></font></p> 
    </TD> 
    <TD bgColor=#000000 width="123"> 
    <p align="left"><font color="#ffffff" face="Verdana" size="1"><b>Poster</b></font></p> 
    </TD> 
    </tr>


    EOD;

    $file_pointer fopen($file_name"w"); 
    $lock flock($file_pointerLOCK_EX); 

    if (
    $lock){
     
    fputs($file_pointer$contents); 
     
    flock($file_pointerLOCK_UN); 

    fclose($file_pointer); 


    echo <<<EOD

    <html>
    <head>
    <META HTTP-EQUIV="Refresh" Content="3; URL=$file_name">
    </head>
    <body>
    Loading your page please wait...
    </body>
    </html>

    EOD;
    }
    ?>

    Basically I combined the two files into one and then printed out a meta refresh tag to redirect the user to the page they just created.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    your'e welcome.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #8
    New Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cheers spookster, nice one

  • #9
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question need help

    hi there,
    i want your help,
    i want php script for store my all forum into any txt file on ptf i m new in php so i cant understend that how i can do it or how it posible,
    please help me about it
    thinking full to you
    zhggu


  •  

    Posting Permissions

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