I am having trouble deleting a file from the server when the delete record is set. Can someone take a look at this and tell me where I'm going wrong? 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']; } PHP:
I suggest printing out the full path of the file you're trying to delete to make sure the file location is actually correct. Also, why are you checking if one file exists before deleting a separate file? You're using two separate variables for the end of the path. You're checking if "$image_path.$_POST['empl_id']" exists and then deleting "$image_path.$row_getApp['empl_dnld_fn']"
I tested the location, and it's pointing to the right place. So your recommendation would be to do this to delete the file?: 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/'; unlink($image_path.$row_getApp['empl_dnld_fn']); ....
zerxer is right, you are checking for one file, but then deleting the other. It's not clear from your snippet which one is correct, but they should be the same, either: if ((isset($_POST['empl_id'])) && file_exists($image_path.$_POST['empl_id'])) { unlink($image_path.$_POST['empl_id']); } PHP: or if ((isset($_POST['empl_id'])) && file_exists($image_path.$row_getApp['empl_dnld_fn'])) { unlink($image_path.$row_getApp['empl_dnld_fn']); } PHP: