Hello all,
I have made a file upload system (storing info in database). I also added a page where user gets to see the files he/she has added. Below every file I have given an option for them to delete the file.
My problem here is I am not able to delete the file and remove the entry from the DB too. Could you please help me with this?
This is my my_uploads.php page where use sees the file he has uploaded with the time of upload being fetched from DB.
<?php
include $_SERVER["DOCUMENT_ROOT"].'/TestSite/core/init.php';
faculty_protect_page();
include $_SERVER["DOCUMENT_ROOT"].'/TestSite/includes/overall/header.php';
?>
<center><h3>My Uploads</h3></center><br/>
<?php
$uid=$faculty_data['faculty_id'];
$query="SELECT * FROM uploads";
$result=mysql_query($query);
while($row=mysql_fetch_assoc($result))
{
if($uid==$row['faculty_id'])
{
echo '<form action="delete.php" method="POST">';
echo "<strong>File: </strong>";
$url=$row['link'];
$new="http://ankursinha.net/TestSite/fileshare/".$url;
echo "<a href='$new'>$new</a><br/>";
echo "<strong>On: </strong>".$row['datetime'];
echo '<br><input type="submit" name="delete" class="btn btn" value="Delete File"/>';
echo '<hr>';
echo '</form>';
}
}
?>
<center>List of files sorted by date</center>
<?php include $_SERVER["DOCUMENT_ROOT"].'/TestSite/includes/overall/footer.php'; ?>
And my delete.php action file which is supposed to delete the file and remove the file name and it’s entries from DB:
<?php
include $_SERVER["DOCUMENT_ROOT"].'/TestSite/core/init.php';
if(isset($_POST['delete']))
{
unlink($new);
$query="DELETE FROM uploads WHERE link = '$url'";
$result=mysql_query($query);
header('Location: my_uploads.php');
exit();
}
else {
echo '<script type="text/javascript">alert("Oops something went wrong!")</script>';
header('Location: my_uploads.php');
exit();
}
?>
Thank you