PDA

View Full Version : Help deleting file from server


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

Please can somebody help me with my script.
The idea is that it first deletes the file off the server and then deletes all the table info for the according details, which include the stored url of the file.

I cannot get the file to delete off server mind.

Many Thanks for any hep,
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));
}

davidj
11-30-2010, 11:57 AM
make sure the path to the file is correct

I would use an absolute path...

/root/path/path/file.ext

or if your on a linux system you could use...

system('rm -f /path/file.ext');