//author:heaven
//文件下载
function download($file_dir,$file_name)
//参数说明:
//file_dir:文件所在目录
//file_name:文件名
{
$file_dir = chop($file_dir);//去掉路径中多余的空格
//得出要下载的文件的路径
if($file_dir != '')
{
$file_path = $file_dir;
if(substr($file_dir,strlen($file_dir)-1,strlen($file_dir)) != '/')
$file_path .= '/';
$file_path .= $file_name;
}
else
$file_path = $file_name;
//判断要下载的文件是否存在
if(!file_exists($file_path))
{
echo '对不起,你要下载的文件不存在。';
return false;
}
$file_size = filesize($file_path);
header("Content-type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Accept-Length: $file_size");
header("Content-Disposition: attachment; filename=".$file_name);
//echo file_get_contents($file_path);
$fp = fopen($file_path,"r");
$buffer_size = 1024;
$cur_pos = 0;
while(!feof($fp)&&$file_size-$cur_pos>$buffer_size)
{
$buffer = fread($fp,$buffer_size);
echo $buffer;
$cur_pos += $buffer_size;
}
$buffer =@fread($fp,$file_size-$cur_pos);
echo $buffer;
fclose($fp);
return true;
}
页面处理部分
$dir = "../main/trade_log";
// Open a known directory, and proceed to read its contents
if (is_dir($dir))
{
$filename=array();
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if ($file!="." && $file!=".." && $file!=".svn")
{
$filename[]=$file;
}
}
closedir($dh);
}
}
if(isset($_GET['logname']))
{
download("../main/trade_log",$_GET['logname']);
exit;
}
$smarty->assign("trade_log_list",$filename);
注意这块
download("../main/trade_log",$_GET['logname']);
exit;
一定要加exit
否则下载的文件display的部分也要输出

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン
