#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    4
    Rep Power
    0
    I am new to PHP and more importantly, to programing.

    I am getting my feet wet, so to speak, by attempting to create templates for existing websites, where the owner of the site can bring up a form and input the variables that they wish to change.

    This information would then be passed to a PHP file that would open a template file and merge the variables into the proper place, then output the file to a standard HTML file.

    So far I have gotten everything to work except for having the new "merged" information written to a file.

    When the information from the "Form" page is sent to the "update.phtml" page containing the following code:
    ---------------------------------
    <?
    $template = include("./calendartemplate.phtml");
    $content = $template;
    if (!$fp = fopen("./calendar_test.html" , "w")) {
    print("Could not open file!");

    } else {

    fputs($fp, $content);
    fclose($fp);
    print ("<P>&nbsp;<B>" .
    "File Saved Successfully." .
    "</B>");
    }

    ?>
    ---------------------------------
    No error is produced, all the information is displayed on the page (with the variables in place), but when I go to look at the "calendar_test.html" page the only thing that is on the page is a "1" in the upper left corner.

    Can someone tell me what I'm missing? From everything that I have read it should be working. I figure it's probably something simple. I am using "Professional PHP Programing" as a reference.

    Thanks!

    [This message has been edited by BEDesigns (edited April 24, 2000).]

    [This message has been edited by BEDesigns (edited April 24, 2000).]
  2. #2
  3. No Profile Picture
    ads
    Guest
    Devshed Newbie (0 - 499 posts)
    I also faced simillar problem and ended up in displaying .php file only. I was getting error while copying file "permission denied in *** directory." myt ISP said he has given all permissions. Also I gave all permissions to both files. But could not help.
    Give what code you are using for file copy.
  4. #3
  5. No Profile Picture
    ads
    Guest
    Devshed Newbie (0 - 499 posts)
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by ads:
    I also faced simillar problem and ended up in displaying .php file only. I was getting error while copying file "permission denied in *** directory." myt ISP said he has given all permissions. Also I gave all permissions to both files. But could not help.

    [/quote]

  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    4
    Rep Power
    0
    Thanks for the reply, however, I am not trying to copy a file.

    I have a template file and a form that collects the information. the information that is collected is then merged with the template.

    Everything works fine until this point. The message that is associated with the PHP coding (File Saved Successfully) is displayed indicating that everything is as it sholud be. However the output file (calendar_test.html) contains only "1".

    I am stumped at this point.

    Thanks!

    [This message has been edited by BEDesigns (edited April 25, 2000).]
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    24
    Rep Power
    0
    I know what you problem is. You had cody like this in your program
    <?
    $template = include("./calendartemplate.phtml");
    $content = $template;
    ?>

    in that section of code is your problem. When you wrote $template = include("./calendartemplate.phtml"); $templet is being set to the value 1 if the file is included; 0 if not. Because the file was included the value of $template was set to one then youe set $content=$template wchich sets $content to the value of one. then when you write it out to the file you bacily replace everything in the file with the number 1
  10. #6
  11. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    $templet is being set to the value 1 if the file is included; 0 if not. Because the file was included the value of $template was set to one then youe set $content=$template wchich sets $content to the value of one.


    That is what happend their.

    He should read the values from "calendartemplate.phtml" and then it should write to another file .for that you should use fopen().then read the values to the $content variable."Include" won't work for that.


    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited June 20, 2000).]
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    4
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by Shiju Rajan:

    $templet is being set to the value 1 if the file is included; 0 if not. Because the file was included the value of $template was set to one then youe set $content=$template wchich sets $content to the value of one.


    That is what happend their.

    He should read the values from "calendartemplate.phtml" and then it should write to another file .for that you should use fopen().then read the values to the $content variable."Include" won't work for that.

    [/quote]

    I have changed the code to the following:

    ==========================================
    <?

    $template = "./calendartemplate.phtml";
    $fd = fopen($template, "r");
    $content = fread($fd, filesize($template));
    fclose($fd);

    $fp = fopen("./calendar_test.html" , "w");
    fputs($fp, $content);
    fclose($fp);
    print ("<P Align=Center> <B>" .
    "File Saved Successfully." .
    "</B> <P>");

    print $content;

    ?>
    ============================================
    it now writes to the file but the variables are not included. I'm going nuts trying to figure this out.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    43
    Rep Power
    15
    Perhaps the problem is not understood. I think you are saying this:
    1. Site owner brings up a form of variable's they want to edit.
    2. When they are done they submit the form to your PHP script called update.phtml.
    3. update.phtml must open a template file and insert the variables into the proper places and write the results to an HTML file.
    Is this what you are doing?
    If so then you have code in place for reading and writing files but I see nothing related to putting the variables from the site owner into the template fields.
    When the variables are passed to you from the form what are you doing with them? If you know the name of the variables then you could do something like this:
    $content = eregi_replace("keyinfo",$newInfo,$content);
    which will replace the string "keyinfo" with the value of the variable $newInfo in the string $content.
    Hope this helps. If not please explain how you handle your variables from the user's form.


    ------------------
    webpatron.com
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    4
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by lhallusa:
    Perhaps the problem is not understood. I think you are saying this:
    1. Site owner brings up a form of variable's they want to edit.
    2. When they are done they submit the form to your PHP script called update.phtml.
    3. update.phtml must open a template file and insert the variables into the proper places and write the results to an HTML file.
    Is this what you are doing?
    If so then you have code in place for reading and writing files but I see nothing related to putting the variables from the site owner into the template fields.
    When the variables are passed to you from the form what are you doing with them? If you know the name of the variables then you could do something like this:
    $content = eregi_replace("keyinfo",$newInfo,$content);
    which will replace the string "keyinfo" with the value of the variable $newInfo in the string $content.
    Hope this helps. If not please explain how you handle your variables from the user's form.

    [/quote]

    YES! Basically you got it.
    1. Right now the user would go to the update page. They will be changing Upcoming Events. The update page asks them how many events they wish to add. So they enter "5". The page returns a form page to them that has 10 input fields ( Date & Event Description for each event).

    2. Once they have the information completed they submit the form the variables which are in an array,are passed to "calendarupdate.phtml" which contains the following code (complete):

    =======================================================
    <Center>
    <table border=0 cellspacing=0 cellpadding=0 width=620><tr
    valign=top align=left><td width=620><p align=center>
    <form name="LAYOUTFORM" action="" METHOD=POST>
    <input TYPE=HIDDEN name="date" value="<? print ($date); ?>">
    <input TYPE=HIDDEN name="event" value="<? print ($event); ?>">

    <?

    $template = "./calendartemplate.phtml";
    $fd = fopen($template, "r");
    $content = fread($fd, filesize($template));
    fclose($fd);

    $fp = fopen("./calendar_test.html" , "w");
    fputs($fp, $content);
    fclose($fp);
    print ("<P Align=Center> " .
    "File Saved Successfully." .
    " <P>");

    print $content;

    ?>

    <p> </td></tr></form></table>

    =======================================================

    3. On the "calendartemplate.phtml page I have the following code to process the variables:

    =======================================================

    Last Updated: <? print (date("l, F jS, Y")); ?>


    <?
    $num_events = count ($date);

    print ("<BR>");
    print ("<Font Face=Arial>n");

    for ($idx = 0; $idx < $num_events; ++$idx){
    // Print each event on it's own line:

    $HTML_safe_text = nl2br(htmlentities($event[$idx]));
    print ("<Font Color=Yellow><B>$date[$idx] - </Font></B> n");
    print ("$HTML_safe_text <P>n");

    }

    print ("</Font>n");
    ?>

    =======================================================

    Using the include the information displays correctly in the browser, but does not write to the file, using the fopen it displays in the browser and writes to the file WITHOUT the variables.

    Hopefully this will give a better picture.

    ------------------


    [This message has been edited by BEDesigns (edited June 29, 2000).]
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    43
    Rep Power
    15
    I think I see whats going on but please bear with me as I'm not sure exactly what the desired affect is.
    When you use the include function the file is rendered to the browser and the PHP is executed. Also the variables will be recognized from the input form.
    When using fopen the PHP does not execute within the opened file but you can read or write a file. Therefore you must create a variable that collects the form variables similar to the way you print them out in the for loop. Then you will need to combine the information. Let me ask a few more questions.
    1. Do you continuously add the new information and retain the old information in the file?
    2. Is the contents you show for the calendartemplate.phtml file all there is in that file?
    If so then consider eliminating the calendartemplate.phtml file and inserting that code ahead of the fopen. I have a crude example to show here which could be improved on but may get the idea:
    -----------------------------------------
    <?php
    // collect variable data and print
    $currentDate = date("l, F jS, Y");
    $num_events = count ($date);
    $newText = "";

    $newText .= "Last Updated: $currentDate"

    $newText .= "<BR>";

    $newText .= "<Font Face=Arial>";
    for ($idx = 0; $idx < $num_events; ++$idx){
    // Print each event on it's own line:

    $HTML_safe_text = nl2br(htmlentities($event[$idx]));

    $newText .= "<Font Color=Yellow><B>$date[$idx] - </Font></B>";

    $newText .= "$HTML_safe_text <P>";
    }

    $newText .= "</Font>";

    $template = "./calendar_test.html";
    $fd = fopen($template, "r");
    $content = fread($fd, filesize($template));
    fclose($fd);

    $fp = fopen("./calendar_test.html" , "w");
    $content = "$newText $content";
    fputs($fp, "$content");
    fclose($fp);
    print ("<P Align=Center> " .
    "File Saved Successfully." .
    " <P>");

    // read out file and display to browser.

    readfile("./calendar_test.html");

    ?>

    --------------------------------------
    This totally eliminates the calendartemplate.phtml file and processes everything up front. The $newText variable will contain the user variable. The only file changed is the calendar_test.html file I don't know if this solves anything but it keep adding events to the calendar_test.html file.
    Hope this is more help than hinder.
    The new information should be at the beginning of the file in reverse chronological order.
    If this doesn't meet your needs then maybe there is a few examples in the code that are useful to you.


    [This message has been edited by lhallusa (edited June 30, 2000).]

    [This message has been edited by lhallusa (edited June 30, 2000).]

    [This message has been edited by lhallusa (edited June 30, 2000).]

Similar Threads

  1. writing a file to a ftp server
    By buddinghere in forum FTP Help
    Replies: 1
    Last Post: February 12th, 2004, 10:36 AM
  2. Pointer problem in opening a file
    By LAKI in forum C Programming
    Replies: 13
    Last Post: February 11th, 2004, 08:27 AM
  3. Replies: 1
    Last Post: February 8th, 2004, 01:59 PM
  4. Upload file name problem
    By clio in forum PHP Development
    Replies: 1
    Last Post: February 6th, 2004, 06:19 AM
  5. Problem with opening a file
    By Psantiago in forum C Programming
    Replies: 3
    Last Post: February 3rd, 2004, 07:31 PM

IMN logo majestic logo threadwatch logo seochat tools logo