SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    823
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question Delete File from server with PHP

    I have a delete file record form that deletes records from a database, but how do I delete the file from the server after 'submit' has been carried out?

    Code HTML4Strict:
    <form id="delRecord" name="delRecord" method="post" action="">
    <p><strong>File:</strong> <?php echo $row_getFile['office_dnld_title']; ?></p>
    <p><strong>Filename:</strong> <?php echo $row_getFile['office_dnld_fn']; ?></p>
    <p>
    <input name="office_dnlds_id" type="hidden" id="office_dnlds_id" value="<?php echo $row_getFile['office_dnlds_id']; ?>" />
    <input name="delete" type="submit" id="delete" value="Confirm Deletion" />
    </p>
    </form>

    Code PHP:
    if ((isset($_POST['office_dnlds_id'])) && ($_POST['office_dnlds_id'] != "")) {
      $deleteSQL = sprintf("DELETE FROM office_dnlds WHERE office_dnlds_id=%s",
                           GetSQLValueString($_POST['office_dnlds_id'], "int"));
     
      mysql_select_db($database_wvgsadmin, $wvgsadmin);
      $Result1 = mysql_query($deleteSQL, $wvgsadmin) or die(mysql_error());
     
      $deleteGoTo = "office_dnld_list.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
        $deleteGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $deleteGoTo));
    }
     
    $colname_getFile = "-1";
    if (isset($_GET['office_dnlds_id'])) {
      $colname_getFile = $_GET['office_dnlds_id'];
    }
    mysql_select_db($database_wvgsadmin, $wvgsadmin);
    $query_getFile = sprintf("SELECT * FROM office_dnlds WHERE office_dnlds_id = %s", GetSQLValueString($colname_getFile, "int"));
    $getFile = mysql_query($query_getFile, $wvgsadmin) or die(mysql_error());
    $row_getFile = mysql_fetch_assoc($getFile);
    $totalRows_getFile = mysql_num_rows($getFile);

  2. #2
    SitePoint Guru
    Join Date
    Feb 2008
    Posts
    655
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To delete a file in PHP you need to use the unlink function.

  3. #3
    SitePoint Evangelist simshaun's Avatar
    Join Date
    Apr 2008
    Location
    North Carolina
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    Non-Member
    Join Date
    Mar 2008
    Location
    USA, New York--Born in India
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for the information about the unlink stuff, im grateful!


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
  •