Question : How do I delete a file from a folder (uploads directory) when I delete its reference in the database?

I have a mysql database table that stores data referencing the file. When I successfully delete a file from the database, I want to simultaneously delete the file from the uploads folder(to which the file was initially uploaded).
I am using windows xp and even though I have gone through a few similar solutions on our Experts Exchange, especially ID:24958826Author: rcimasi Date:12/08/09 ", I fail. I use the path and unlink() function. Can anyone please help me sort out this issue?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
<?php 
$id = $_GET['id'];
$n = $_GET['name_file'];
$file_to_delete = 'xxxxx/'.$n;//path including filename
require_once('../../xxxx/connect.php');
	
$error = "";

if ($_GET) {
		if (isset($_GET['id'])) {
			$deleteQuery = 'DELETE FROM xxxxx WHERE id = '. mysql_real_escape_string(urldecode($_GET['id']));			

			if ($result = mysql_query($deleteQuery)) {
				echo "<script language=\"JavaScript\">alert ('$n deleted successfully');
                location.replace(\"xxx.php\");
         </script>";							
			}else {
				$error .= '<font color=red><i>Sorry, there was an error Deleting $n<br>' . (mysql_error()) . '</i></font><br>';
			}
		}
	}
if($result) {
unlink($file_to_delete);
        echo 'Done!<br />';
}

?>

Answer : How do I delete a file from a folder (uploads directory) when I delete its reference in the database?

Regarding this...

Is it possible that I've made some mistake with the path ($file_to_delete = 'files_upload/'.$name;)

Why not print out the value of the variables and see what they contain?
Random Solutions  
 
programming4us programming4us