PDA

View Full Version : Trying to delete image file from server


Stevis2002
11-19-2010, 12:02 PM
Hi all,

I have managed to create a script that deletes a set of information from my database, but i also want it to delete a file on my server, but i cannot get that sectiojn of code working.
Please can somebody take a look at it?

Thanks,
Steve


$query_Recordset1 = "SELECT Images FROM testimonials WHERE Testimonial_Id=%s";

$img_dir = 'uploaded_images/';
$image_name = $row_RecordSet1['Images'];

if ((isset($_GET['del'])) && ($_GET['del'] != "")) {

unlink($img_dir.$image_name);

$deleteSQL = sprintf("DELETE FROM testimonials WHERE Testimonial_Id=%s",
GetSQLValueString($_GET['del'], "int"));

mysql_select_db($database_localhost, $localhost);
$Result1 = mysql_query($deleteSQL, $localhost) or die(mysql_error());

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

gentleone
11-19-2010, 12:29 PM
Moved to PHP forum and wrapped in php code tags.

Stevis2002
11-19-2010, 12:32 PM
Moved to PHP forum and wrapped in php code tags.

Thank You, wasn't sure where to put it

davidj
11-20-2010, 07:08 PM
unlink is correct

echo out your path variables

echo $img_dir.$image_name;
And see if the path is correct