you need to add a download count to order details table, set the default value for the new download count column to 0
in the download file server behavior, set the download counter section to use the new download countcount column, this will increment that comlumn each time the file is downloaded.
make sure that the new download count column is returned by the recordset on the download cewnter page with the rest of the order detaisl table.
then add an if statement around the download button to only show it if the download count is 5 or less:
<?php if($row_recordsetName['downloadcount'] <= "5") { ?>
<download button>
<?php } ?>