SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Wizard
    Join Date
    May 2002
    Posts
    1,370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    POST form to edit existing files, features

    Could someone please look at the following form code. Files write but:

    ***how to; limit number of bytes being written/posted

    ***also need to add date of this edit into mySQL table with:
    <input type="hidden" name="RetEdit" value="<?php echo date('Y-m-d', strtotime("+0 days")); ?>">

    PHP Code:
    <?php
    // umask to maintain file permissions during next procedure 
    umask(000); 
    $filename $row_Recordset_rs['ReID'].'__r.txt';
    $fullfilename=$_SERVER['DOCUMENT_ROOT']."/file3/".$filename
    if (
    file_exists($fullfilename)) { 
    if (isset(
    $_POST['submit']) && isset($_POST['contents'])) { 
    if (
    is_writable($fullfilename)) { 
    if (
    $fp fopen($fullfilename'wb')) { 
    $bytes fwrite($fp$_POST['contents']); 
    if (
    $bytes === false) { 
    echo 
    "Error: could not write to file '{$fullfilename}'"

    else { 
    echo 
    "{$bytes} bytes written to file '{$fullfilename}'"

    fclose($fp); 

    else { 
    echo 
    "Error: could not open file '{$fullfilename}' for writing"


    else { 
    echo 
    "Error: file '{$fullfilename}' is not available for writing"


    else { 
    if (
    is_readable($fullfilename)) { 
    echo 
    '<form action= "' $_SERVER['PHP_SELF'] . '" method="post">' 
    '<textarea name="contents" rows="15" cols="80">' 
    //for PHP 4.3.0 or newer, which this server has 
    htmlspecialchars(file_get_contents($fullfilename)) 
    '</textarea><br />' 
    '<input type="submit" name="submit" value="Update Q"></form>' 
     

    else { 
    echo 
    "Error: could not open file '{$fullfilename}' for reading"



    ?>






    Last edited by datadriven; Apr 15, 2004 at 12:44.


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
  •