Reputation: 21
Below is my code for downloading some files from a webpage.
Everything works fine except target="_blank"
. This button does nothing even though the link is correct. If I right click and press open in a new tab it works but when i press the button it does nothing.
<?php
while ($row = $result->fetch_assoc()) {
$i+=1;
$name = $row["filename"];
$location = "../uploadedfiles/" . $name;
?>
<div class="row">
<p><hr>Name : <?php echo $row["name"] ?> <br> Contact Details : <?php echo $row["number"] ?><br></p>
</div>
<div class="row">
<p>Date Sent: <?php echo date("F d Y-- H:i:s.", filectime($location)) ?><br></p>
</div>
<div class="row">
<p><p> <?php echo $i ?> ) <?php echo substr($name, 10) ?> <a href="../uploadedfiles/<?php echo $name; ?>" target='_blank'><button type='button' class='btn btn-info'>View / Download </button></a></p></p>
</div>
<?php }
?>
<hr>
<?php
} else {
echo "0 results";
}
$con->close();
Upvotes: 1
Views: 1603
Reputation: 971
The way you have created button within the anchor tag is not one of the best practices to be followed.
Ideally you should do something like this:
<a href="../uploadedfiles/<?php echo $name; ?>" target="_blank" class="btn btn-info">View/Download</a>
Hope this helps.
Upvotes: 3