I just want to make a suggestion of making the Delete, an onclick event so it can also be done in ajax.
the line:
header("Location: $homepage");
refreshes the page, and the uploaded files in id2 and id3 (suppose you delete file in id1) are no longer seen on the page.