[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 02-23-2007, 01:30 PM   #1 (permalink)
Senior Member
 
Join Date: May 2005
Location: Ontario Canada
Posts: 2,928
1,675.13 NP$ (Donate)

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 behold


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");
        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($fp, filesize($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>
                    <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, 01:41 AM   #2 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

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" >
                                <?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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 12:11 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85