SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    UK
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sidewide basic html editor

    hi all
    I am trying to create a very simple/basic online sidewide html/PHP editor, i have a form which inputs the variable $editfile, which is the path to the file (ie ../articles/alancohen/article62.php), the script opens the file without a problem and i can change the text in the textarea, however when i click on the edit button at the bottom i get these error's


    Warning: fopen("../articles/alancohen/article62.php", "w+") - Permission denied in /home/.sites/28/site1/web/editing/edit.php on line 27

    Warning: fwrite(): supplied argument is not a valid File-Handle resource in /home/.sites/28/site1/web/editing/edit.php on line 28

    Warning: fclose(): supplied argument is not a valid File-Handle resource in /home/.sites/28/site1/web/editing/edit.php on line 29

    and the file does not get updated with the new text in the textarea,
    any ideas?
    cheers
    steve

    PHP Code:
    <html>
    <head><title>Edit Page</title></head>
    <body bgcolor="#cccccc" text="#000000" link="#000000" alink="#000000" vlink="#000000">
    <font face="verdana, arial, helvetica" size=2>

    <?PHP 
        
    if ($_POST['pw']!="") {$pw=$_POST['pw'];}else{$pw=$_GET['pw'];}
        
    $newcontent=$_POST['newcontent'];
        
    $filelocation "$editfile";
        if (!
    file_exists($filelocation)) {
        echo 
    "Couldn't find datafile, please contact administrator!";
        }
        else {
        
    $newfile fopen($filelocation,"r");
        
    $content fread($newfilefilesize($filelocation));
        
    fclose($newfile);
        }
        
    $content stripslashes($content);
        
    $content htmlentities($content);
        
    $pass="password";
        if (!
    $pw || $pw != $pass){
        
    $content nl2br($content);
        }
        else {
            if (
    $newcontent){
                
    $newcontent stripslashes($newcontent);
                
    $newfile fopen($filelocation,"w+");
                
    fwrite($newfile$newcontent);
                
    fclose($newfile);
                echo 
    "Text was edited.<form><input type=\"submit\" value=\"see changes\"></form>";    
                }
                    else{
                    echo 
    "<form method=\"post\">
                    <textarea name=\"newcontent\" cols=50 rows=15 wrap=\"virtual\">"
    ;
                    echo 
    $content;
                    echo 
    "</textarea><input type=\"hidden\" name=\"pw\" value=\"$pass\"><br><input type=\"submit\" value=\"edit\"></form>";
                    }
            }    

    ?>
        
    </font>
    </body>
    </html>

  2. #2
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dreams3577
    hi all
    I am trying to create a very simple/basic online sidewide html/PHP editor, i have a form which inputs the variable $editfile, which is the path to the file (ie ../articles/alancohen/article62.php), the script opens the file without a problem and i can change the text in the textarea, however when i click on the edit button at the bottom i get these error's


    Warning: fopen("../articles/alancohen/article62.php", "w+") - Permission denied in /home/.sites/28/site1/web/editing/edit.php on line 27

    Warning: fwrite(): supplied argument is not a valid File-Handle resource in /home/.sites/28/site1/web/editing/edit.php on line 28

    Warning: fclose(): supplied argument is not a valid File-Handle resource in /home/.sites/28/site1/web/editing/edit.php on line 29

    and the file does not get updated with the new text in the textarea,
    any ideas?
    cheers
    steve

    PHP Code:
    <html>
    <head><title>Edit Page</title></head>
    <body bgcolor="#cccccc" text="#000000" link="#000000" alink="#000000" vlink="#000000">
    <font face="verdana, arial, helvetica" size=2>

    <?PHP 
        
    if ($_POST['pw']!="") {$pw=$_POST['pw'];}else{$pw=$_GET['pw'];}
        
    $newcontent=$_POST['newcontent'];
        
    $filelocation "$editfile";
        if (!
    file_exists($filelocation)) {
        echo 
    "Couldn't find datafile, please contact administrator!";
        }
        else {
        
    $newfile fopen($filelocation,"r");
        
    $content fread($newfilefilesize($filelocation));
        
    fclose($newfile);
        }
        
    $content stripslashes($content);
        
    $content htmlentities($content);
        
    $pass="password";
        if (!
    $pw || $pw != $pass){
        
    $content nl2br($content);
        }
        else {
            if (
    $newcontent){
                
    $newcontent stripslashes($newcontent);
                
    $newfile fopen($filelocation,"w+");
                
    fwrite($newfile$newcontent);
                
    fclose($newfile);
                echo 
    "Text was edited.<form><input type=\"submit\" value=\"see changes\"></form>";    
                }
                    else{
                    echo 
    "<form method=\"post\">
                    <textarea name=\"newcontent\" cols=50 rows=15 wrap=\"virtual\">"
    ;
                    echo 
    $content;
                    echo 
    "</textarea><input type=\"hidden\" name=\"pw\" value=\"$pass\"><br><input type=\"submit\" value=\"edit\"></form>";
                    }
            }    

    ?>
        
    </font>
    </body>
    </html>
    Warning: fopen("../articles/alancohen/article62.php", "w+") - Permission denied in /home/.sites/28/site1/web/editing/edit.php on line 27

    states that you dont have the rights on the server to write to a file
    try chmod() http://nl2.php.net/manual/en/function.chmod.php
    might help...

    Warning: fwrite(): supplied argument is not a valid File-Handle resource in /home/.sites/28/site1/web/editing/edit.php on line 28

    states that your resource is not good, this is beceause the previous error has occured...

    Warning: fclose(): supplied argument is not a valid File-Handle resource in /home/.sites/28/site1/web/editing/edit.php on line 29

    states idem dito....

    cheers,
    Galo
    Business as usual is off the menu folks, ...

  3. #3
    SitePoint Wizard REMIYA's Avatar
    Join Date
    May 2005
    Posts
    1,351
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Warning: fopen("../articles/alancohen/article62.php", "w+") - Permission denied in /home/.sites/28/site1/web/editing/edit.php on line 27
    Change the directory permissions.


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
  •