Jump to content

Unlink File From Server


toad78

Recommended Posts

I'm trying to delete a file from the server after the deletion is set; the record on the db deletes, but not the file. Can someone take a look at this for me?

 

Thank you!

 

if ((isset($_POST['empl_id'])) && ($_POST['empl_id'] != "")) {
  $deleteSQL = sprintf("DELETE FROM empl_dnlds WHERE empl_id=%s",
                       GetSQLValueString($_POST['empl_id'], "int"));
  
  $image_path = '../../../info/docs/employment/';
  
  if ((isset($_POST['empl_id'])) && file_exists($image_path.$_POST['empl_id'])) {
    unlink($image_path.$row_getApp['empl_dnld_fn']);
  }
  mysql_select_db($database_wvgsadmin, $wvgsadmin);
  $Result1 = mysql_query($deleteSQL, $wvgsadmin) or die(mysql_error());

  $deleteGoTo = "empl_app_list.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
}

$colname_getApp = "-1";
if (isset($_GET['empl_id'])) {
  $colname_getApp = $_GET['empl_id'];
}

Link to comment
https://forums.phpfreaks.com/topic/143841-unlink-file-from-server/
Share on other sites

Try:

if ((isset($_POST['empl_id'])) && ($_POST['empl_id'] != "")) {
  $deleteSQL = sprintf("DELETE FROM empl_dnlds WHERE empl_id=%s",
                       GetSQLValueString($_POST['empl_id'], "int"));

  $image_path = '../../../info/docs/employment/';

  if ((isset($_POST['empl_id'])) && file_exists($image_path.$_POST['empl_id'])) {
    if(!is_file($image_path.$row_getApp['empl_dnld_fn'])){ die('your file path may be wrong dude'); }
    unlink($image_path.$row_getApp['empl_dnld_fn']);
  }
  mysql_select_db($database_wvgsadmin, $wvgsadmin);
  $Result1 = mysql_query($deleteSQL, $wvgsadmin) or die(mysql_error());

  $deleteGoTo = "empl_app_list.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
}

$colname_getApp = "-1";
if (isset($_GET['empl_id'])) {
  $colname_getApp = $_GET['empl_id'];
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.