Reputation: 15
i wanna ask again,still have problems with my php code i wanna ask how to create download link that looping from database, the file store in localhost in folder attach,anyone can help
my php code to show the attachment file store in database like this
<?php
if ($row['filename']==NULL)
{echo "no attachment"; }
else
{echo $row['filename']; }
?>
from that generated i want to create a download link which is stored in my localhost
my attachment like it contains only 2 columns file name and file size
Regards Wahyu
Upvotes: 0
Views: 4088
Reputation: 7145
Can you please explain your question more? Im not able to comment on questions yet, so I have to add an answer.
A general answer is:
In your database your store the filename of the file you want to be downloaded. Next, you generate a link with php and use the filename of the database.
After your edit/comment, something like this:
<?php
if ($row['filename']==NULL){
print "no attachment";
}else{
printf("<a href='yourhost.com/folder/%s'",$row['filename']);
}
?>
Upvotes: 1
Reputation: 3066
For making download link, you need to set appropriate headers. For example
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename='.$filename);
To solve your problem, you can have a link like http://site.com/downloads.php?id=12456. In the downloads.php page. you can check for the file name . and set the header in that page. Also its not necessary to have the content-type header.
Upvotes: 0