Results 1 to 3 of 3

Thread: editing a file online

  1. #1
    Join Date
    Jan 2008
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation editing a file online

    the scenario is that i want to set up a page where my customer can go and update the news section of his website on his own. I'm having a hard time opening and saving the .txt file called news. here's my script:

    PHP Code:
    <?php 
    $loadcontent 
    "files/news.txt"
        if(
    $save_file) { 
            
    $savecontent stripslashes($savecontent); 
            
    $fp = @fopen($loadcontent"w"); 
            if (
    $fp) { 
                
    fwrite($fp$savecontent); 
                
    fclose($fp);
    print 
    '<a href='.$_SERVER[PHP_SELF].'>Refresh</a>'
    print 
    "<html><head><META http-equiv=\"refresh\" content=\"0;URL=$_SERVER[PHP_SELF]\"></head><body>"
     


        
    $fp = @fopen($loadcontent"r"); 
            
    $loadcontent fread($fpfilesize($loadcontent)); 
    $lines explode("\n"$loadcontent);
    $count count($lines);
            
    $loadcontent htmlspecialchars($loadcontent); 
            
    fclose($fp); 
    for (
    $a 1$a $count+1$a++) {
    $line .= "$a\n";
    }
    ?> 
    <form method=post action="<?=$_SERVER[PHP_SELF]?>"> 
    <input type="submit" name="save_file" value="Save">    
    <table width="100%" valign="top" border="0" cellspacing="1" cellpadding="1">
      <tr>
        <td width="3%" align="right" valign="top"><pre style="text-align: right; padding: 4px; overflow: auto; border: 0px groove; font-size: 12px" name="lines" cols="4" rows="<?=$count+3;?>"><?=$line;?></pre></td>
        <td width="97%" align="left" valign="top"><textarea style="text-align: left; padding: 0px; overflow: auto; border: 3px groove; font-size: 12px" name="savecontent" cols="150" rows="<?=$count;?>" wrap="OFF"><?=$loadcontent?></textarea></td>
     </tr>
    </table>
     
    <br> 
    <input type="submit" name="save_file" value="Save">    
    </form>
    all i'm gettin right now is the <?=$loadcontent?> instead the actual text; so some help would be highly appreciated.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try

    Code:
    <?php echo $loadcontent; ?>
    instead of
    Code:
    <?=$loadcontent?>
    Also, don't use global variables, but instead use $_GET, $_POST, $_SERVER, etc global arrays to call your variables.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    you might also want to change this:
    Code:
    <form method=post action="<?=$_SERVER[PHP_SELF]?>">
    to this:
    Code:
    <form method=post action="<?php echo $_SERVER[PHP_SELF]; ?>">
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

Bookmarks

Posting Permissions

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