Hello,
I am using unlink() for the first time to delete files from a server, which appears to be working just fine. However i wish to delete a specific file whose name is coming from a mysql table but instead i am deleting all the files in the specified folder. My code is as follows:
//code to delete the file from the server
$query = "SELECT *
FROM fares
WHERE fare_id = '".$_GET['fare_id']."'";
$result = mysql_query($query, $conn)or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$fare_id = $row['fare_id'];
$doc = $row['doc'];
}
$path = '/srv/www/htdocs/webdev/farebank/fare_uploads/';
$open = opendir($path);
// the script to find the file and to delete the blighter
while($doc = readdir($open)) {
if(is_file($path.$doc)) {
unlink($path.$doc);
echo 'DELETED '.$path.$doc.'<br>';
}
}
I feel that i am close but i just don't know how to make this work. Some help would be greatly appreciated.