Use http://php.net/manual/en/function.unlink.php unlink($filename);
.
You will probably want to get the filename from the database, and validate it's existance. DO NOT blindly trust the user input.
Use http://php.net/manual/en/function.file-exists.php file_exists($filename)
to check if it exists.
So, you end logic should be something like:
- if a filename is submitted, and it's not empty
- then check the filename is in the database
- then check the file exists
- then delete the file
- then delete the row from the database for the file
Something like:
if (isset($_POST['file_name']) && !empty($_POST['file_name'])) {
mysql_select_db($database_attibfn, $attibfn);
$select = ""; // select filename query
$filename = mysql_query($select) or die(mysql_error());
if (!$filename || !file_exists($filename)) {
// Handle it! Throw an exception or something
}
unlink($filename);
$deleteSQL = sprintf(
"DELETE FROM image_carousel WHERE image_name=%s",
GetSQLValueString($_POST['file_name'], "text")
);
$Result1 = mysql_query($deleteSQL, $attibfn) or die(mysql_error());
}
Also, consider using PDO, or at the least - MySQLi.
http://php.net/manual/en/book.pdo.php
http://php.net/manual/en/book.mysqli.php
mysql_*
functions are deprecated and being removed. They are insecure.