这个程序上传的附件都会有个随机码比如:msFSoUx6Rq
然后进入随即码这个页面下载附件
我想问的问题是:怎么在这个随机码后面加上文件的后缀比如: 
msFSoUx6Rq.mp3
也就是说本来下载附件要进入这个页面:
http://localhost/dz555/11/link.php?ref=msFSoUx6Rq
但我想变成进入这个页面:http://localhost/dz555/11/link.php?ref=msFSoUx6Rq.mp3来下载附件db.php这个文件不知道干什么的 
<?php 
class   db 

function   connect($dbhost,   $dbuser,   $dbpwd,   $dbname)   

if(!@mysql_connect($dbhost,   $dbuser,   $dbpwd))   

die('Can   not   connect   to   MySQL   server'); 

return   $this-> select_db($dbname); 
} function   select_db($dbname)   

return   mysql_select_db($dbname); 
} function   fetch_row($query)   

return   mysql_fetch_row($query); 
} function   query($sql)   

$query=mysql_query($sql); 
return   $query; 
} function   go($query,$rec_num) 

mysql_data_seek($query,$rec_num); 

function   close()   { 
return   mysql_close(); 

} ?> 
download.php 
<?php 
require   'config.php'; 
require   'db.php'; 
$db=new   db; 
$db-> connect($dbhost,   $dbuser,   $dbpwd,   $dbname); 
$ref=$_POST['ref']; 
$res=$db-> query("select   count(*)   from   list   where   code='".$ref."'"); 
$count=$db-> fetch_row($res); 
if(!$count[0]) 
{echo   "No   such   file!!";} 
else 

$sql="select   file   from   list   where   code='".$ref."'"; 
$res=$db-> query($sql); 
$tmp=$db-> fetch_row($res); 
$filename=$uploaddir.$tmp[0]; 
$realname=substr($tmp[0],0,-5); 
$str='Content-Disposition:   attachment;   filename="'.$realname.'"'; header("Content-type:   application/force-download"); 
header($str); 
    readfile($filename);   
} ?> 
global.php 这个好象就是生成随机码的文件
<?php 
function   fileext($filename)   { 
return   substr(strrchr($filename,   '.'),   1); 

function   random($length)   { 
$hash   =   ''; 
$chars   =   'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; 
$max   =   strlen($chars)   -   1; 
mt_srand((double)microtime()   *   1000000); 
for($i   =   0;   $i   <   $length;   $i++)   { 
$hash   .=   $chars[mt_rand(0,   $max)]; 

return   $hash; 

?> 
upload.php 
<html> <style   type="text/css"> 
<!-- 
body   { 
background-color:   #000000; 

body,td,th   { 
color:   #FF6600; 

a:link   { 
color:   #FF6600; 

a:visited   { 
color:   #FF6600; 

a:hover   { 
color:   #FF6600; 

a:active   { 
color:   #FF6600; 

--> 
</style> 
<head> 
<title> Web   file   host </title> 
<meta   http-equiv="Content-Type"   content="text/html;   charset=utf-8"> 
<meta   name="description"   content="Web   file   host"> 
<meta   name="keywords"   content="jpg,gif,png,zip,rar,doc,torrent,bt,upload,download,   10M,Google,   AdSense,   for,   money,Google   AdSense   for   visitor,adsl,   multiposte,   radio,   wifi,   routeur,   freeplayer,   freebox,   multiplay,   total,   partiel,   Portail,   portail,   portal,   ,   search   engine,   Free,   free,   E-mail,   e-mail,   Mail,   mail,     Fournisseur     ISP,   I.S.P.,   isp,   i.s.p.,   Internet,   internet,   Internaute,   internaute,   Internautes,   internautes,   France,   france,   free   file   host   -   your   free   network   U   dish   and   no   setup!,Usage   more   safe   and   faster   browser   Firefox."> 
</head> <body   leftmargin="60"> 
<p> <a   href="./index.php"> <b> Now   upload   file! </b> </a> <hr> </p> 
<?php 
require   'global.php'; 
require   'config.php'; 
require   'db.php'; $a=strtolower(fileext($_FILES['file']['name'])); if(!in_array(strtolower(fileext($_FILES['file']['name'])),$type)) 

$text=implode(",",$type); 
echo   "Allowed     file   type     :   ",$text," <br> "; 

else 

$filename=explode(".",$_FILES['file']['name']); 
do{ 
$filename[0]=random(10);   
$name=implode(".",$filename); 
$name1=$name.".file"; 
$uploadfile=$uploaddir.$name1; } 
while(file_exists($uploadfile)); if   (move_uploaded_file($_FILES['file']['tmp_name'],$uploadfile))   { 
$db=new   db; 
$db-> connect($dbhost,   $dbuser,   $dbpwd,   $dbname); 
$sql="insert   into   list   (code,file)   values   ('".$filename[0]."','".$name1."')"; if($db-> query($sql)) 
{echo   " <center> The   fast   download   URL:   <p> ".$patch."link.php?ref=",$filename[0]," </center> <p> <hr> ";} 
else{echo   "failed";} 
} } ?> 
<br> 
<center> 
<span   class="STYLE2"> Powered   By   <a   href=""   target="_blank"> <b> Web   File   host </b> </a> You   can   download   it   <a   href=""   target="_blank"> <b> here </b> </a> 
</center> </body> 
</html> 

解决方案 »

  1.   

    感谢楼上大大的回答,但你似乎弄错了我的意思
    这个应该是附加码生成的文件
    global.php   这个好象就是生成随机码的文件 
    <?php   
    function       fileext($filename)       {   
    return       substr(strrchr($filename,       '.'),       1);   
    }   
    function       random($length)       {   
    $hash       =       '';   
    $chars       =       'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';   
    $max       =       strlen($chars)       -       1;   
    mt_srand((double)microtime()       *       1000000);   
    for($i       =       0;       $i       <       $length;       $i++)       {   
    $hash       .=       $chars[mt_rand(0,       $max)];   
    }   
    return       $hash;   
    }   
    ?>  
    我是想在生成的附加码后面加上文件的后缀,比如上传一个MP3文件,上传后的文件变成msFSoUx6Rq.mp3.file
    然后要进入http://localhost/dz555/11/link.php?ref=msFSoUx6Rq页面才能下载文件
    我要的结果是上传后文件变成msFSoUx6Rq.mp3.mp3.file
    然后要进入http://localhost/dz555/11/link.php?ref=msFSoUx6Rq.mp3页面来下载文件