开发者

Create Download link using PHP from the database

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
  开发者_如何学C  {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


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']);
     }
?>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜