";}mysql_close($dl_in);?>3、 下载页面当文件存在时,下载页面转到要下载的文件,如果发生错误,则显示提示信息。filedown.php3: require("dl_func.php3"); $dl_in=dl_dbconnect(); $strQuery="select url from dl_file where id=$id"; $dl_res=mysql_query($strQuery,$dl_in); if(!($arrfile=mysql_fetch_array($dl_res))){ //选择结果为空 infopage("错误的id号"); exit; }else{ $arr_temp=split("/",$arrfile[url]); $filename=$arr_temp[sizeof($arr_temp)-1]; if(strlen(trim($filename))==0){//文件名称为空 infopage("错误的文件"); exit; }else{ $strQuery="update dl_file set count=count+1 where id=$id"; mysql_query($strQuery,$dl_in); header("Content-type: application/file"); header("Content-Disposition: attachment; filename=$filename");//缺省时文件保存对话框中的文件名称 header("location:$arrfile[url]"); //echo “this is test for echo-download”; } } mysql_close($dl_in);?>实现的原理是filelist.php3显示所有文件的连接,然后根据传递的id来得到文件的名称和路径,通过重新定位来下载文件。以上程序笔者测试过,运行正常。文件url可以是本地的,也可以是其他服务器上的。如果文件内容存储在数据库中,或者文件没有在http和ftp的路径下,解决的方法可以利用将文件的内容echo出来取代header(“location:$arrfile[url]”),由于读取文件方法相对简单,这里不再赘述。
http://www.bkjia.com/PHPjc/532037.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/532037.htmlTechArticle现在有许多站点下载文件都提供了统计功能,本文讨论的是如何使用php实现此功能,对于想隐藏下载文件路径,避免用户直接使用url下载的...