NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page [resolved] PHP editing a file

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 02-23-2007, 02:30 PM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes

PHP editing a file


Hey
can anyone look at the code and tell me whats wrong? the php parts are working..for the most part..but the output is a little weid..the textbox is a little messed up..the first line of the file is spaced weirdly..and the line numbers are a little off...thanks

PHP Code:
<?php
    $dir 
htmlspecialchars(trim($_GET['dir']));
    
$subdir htmlspecialchars(trim($_GET['subdir']));
    
$file trim($_GET['file']);
    
$loadcontent="./$dir/$subdir/$file";
    
//$loadcontent = "./includes/template/style.css";
    
if(isset($_POST['save_file'])) {
        
$savecontent stripslashes($_POST['savecontent']);
        
$fp fopen($loadcontent"w");
????: NamePros.com http://www.namepros.com/programming/297847-resolved-php-editing-a-file.html
        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";
    }
?>
<table border='1' width="30%" align="center">
    <tr>
        <td>
            <table>
                <form method=post action="<?$_SERVER['REQUEST_URI']?>">
                    <tr>
                        <td width="5%" align="right" valign="top"></td><td><input type="submit" name="save_file" value="Save" class="button"></td>
                    </tr>
????: NamePros.com http://www.namepros.com/showthread.php?t=297847
                    <tr>
                        <td width="5%" align="left" valign="top">
                            <pre name="lines" cols="4" rows="<?=$count+3;?>"><?=$line;?></pre>
                        </td>
                        <td width="95%" align="right" valign="top">
                            <textarea name="savecontent" cols="80" rows="<?=$count;?>" class="textarea" >
                                <?php echo $loadcontent;?>
                            </textarea>
                        </td>
                    </tr>
                    <tr>
                        <td width="5%" align="right" valign="top"></td><td><input type="submit" name="save_file" value="Save" class="button"></td>
                    </tr>
                </form>
            </table>
        </td>
    </tr>
</table>
heres the css for textbox:
Code:
.textarea {
        background: #a3bed9;
        color: #252525;
        font-family: Tahoma;
        font-size: 11px;
        border-width: 1px;
        border-color: #373737;
        border-style: dashed;
       width: 100%
       height: 100%:
}
unknowngiver is offline  
Old 02-24-2007, 02:41 AM   #2 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Just tried it myself and I presume you mean the extra line at the top of the textarea?

If this is the case it is the html that is causing it replace the following lines :-

PHP Code:
                            <textarea name="savecontent" cols="80" rows="<?=$count;?>" class="textarea" >
????: NamePros.com http://www.namepros.com/showthread.php?t=297847
                                <?php echo $loadcontent;?>
                            </textarea>
With the following line:-

PHP Code:
<textarea name="savecontent" cols="80" rows="<?=$count;?>" class="textarea" ><?php echo $loadcontent;?></textarea>
Peter is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 02:57 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger