-1
如何從文件夾中刪除單個文件?當我點擊我的刪除鏈接時,它會從文件夾中刪除所有上傳的文件。如何從文件夾中刪除單個文件?
鏈接:
<td><a href="Ad_delete.php?$Id=<?php echo $Row['Id'];?>" onClick="return confirm('Are you sure you want to delete this selected file ?')">Delete</a>
代碼:
<?php
// Including the database connection file
include_once 'Ad_updbconnect.php';
// Getting Id of the data from url
$Id = $_GET['Id'];
$Del = glob('uploads/*'); // Get all file names
foreach ($Del as $File) {
if (is_file($File)) {
unlink($File); // delete file !
}
}
// Deleting the row from table
$Result = mysqli_query ($Con, "DELETE FROM ibgsec_uploads WHERE Id=$Id");
$Row = mysqli_fetch_array($Result);
// Redirecting to the display page.
header("location: Ad_uploads.php");
?>
這是留給我工作的唯一的東西,我試過很多方法來正確地執行命令,但它不起作用。