當前位置:編程學習大全網 - 網站源碼 - 在thinkphp中怎樣實現點擊壹張圖片下面的超鏈接“下載”實現這張圖片的下載功能?求代碼、、

在thinkphp中怎樣實現點擊壹張圖片下面的超鏈接“下載”實現這張圖片的下載功能?求代碼、、

可參照如下代碼

imageAction.php

<?php

//數據庫部分自己改

$link=mysql_connect("localhost","root","123456");

mysql_select_db('test',$link);

mysql_query("set names gb2312"); <br>

$recid = $_GET['recid'];

$query="select * from tb_tpsc where id = $recid";

$result=mysql_query($query);

$info = mysql_fetch_array($result);<br>

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

header("Cache-Control: post-check=0, pre-check=0", false);

header("Pragma: no-cache");

header('Content-Type: image/jpeg');

//想辦法獲取文件擴展名,我這裏默認的給的是jpeg的,這個妳沒有存起來

header("Content-Disposition:filename=". $info['tpmc'] . ".jpeg");

echo $info['file'];

>

在模板裏面寫:<a href="路徑/imges/recid/圖片文件的id">下載</a>

具體的代碼以及傳遞的參數,依據妳的實際應用修改。

  • 上一篇:分時周期指示器源代碼
  • 下一篇:如何打有錢麻將?
  • copyright 2024編程學習大全網