I have a problem regarding the deletion of two files (both with the same file name) in two diffrent folders. I tried using the unlink function for deletion. How can i delete these two files in these two different folders using PHP unlink function?
Can anyone guide me on how to use array_intersect
to find the files, push those into array and run a foreach loop over that array to delete using unlink?
Below is my code:
<?php
$i = 1;
$files = scandir("upload_dms_file/uploads_meeting_document");
$files_2 = scandir("upload_dms_file/uploads_filing_file");
$date = $files[$a];
for ($a = 2; $a < count($files); $a++) {
?>
<tr>
<td> <?php echo $i++; ?></td>
<td> <a href="upload_dms_file/uploads_meeting_document/<?php echo $files[$a]; ?>" target="_blank"> <?php echo $files[$a]; ?></a></td>
<td>
<button class="btn btn-sm btn-primary"><a href="upload_dms_file/uploads_meeting_document/<?php echo $files[$a]; ?>"
download="<?php echo $files[$a]; ?>" style="color: white;">
Download</a></button>
   
<button class="btn btn-sm btn-primary"><a
href="upload_dms_file/delete_meeting_document.php?name=uploads_meeting_document/<?php echo $files[$a]; ?>" style="color: white;">
Delete
</a></button>
</td>
</tr>
<?php
} ?>
Below is my deletion code, it succeeds deleting the file in the uploads_meeting_document folder, so my question is how to delete the other copy of the file located in the uploads_filing_file (variable is $files_2) folder?
<?php
unlink($_GET["name"]);
// Redirecting back
header("Location: " . $_SERVER["HTTP_REFERER"]);
?>
Below is my output: