请高手大哥帮忙,小弟先谢谢了!!问题1、这个程序上传的附件都会有个随机码http://localhost/dz555/11/link.php?ref=msFSoUx6Rq然后进入随即码这个页面下载附件
我想问的问题是:怎么在这个随机码后面加上文件的后缀比如:
http://localhost/dz555/11/link.php?ref=msFSoUx6Rq.mp3问题2、本地测试、服务器测试上传附件都经常出现失败,请高手帮忙查看是哪里出问题了
我把整个程序文件的代码帖出来(不是很大):
config.php
<?php
$dbhost="localhost";            //主机名
$dbuser="root";                 //用户名
$dbpwd="";                 //数据库密码
$dbname="";                //数据库名
$uploaddir = "./upload/";       //上传目录
$type=array("jpg","gif","png","zip","rar","doc","torrent");   //允许得文件类型
$patch="http://localhost/dz555/11/"                           //链接地址开头
?>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.   

    还有两个文件
    link.php
    <html>
    <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">
    <style type="text/css">
    <!--
    .STYLE1 {
    color: #FF6600;
    font-size: 16px;
    font-weight: bold;
    }
    .STYLE2 {
    color: #FF6600;
    font-size: 24px;
    font-weight: bold;
    }
    body,td,th {
    color: #FF6600;
    }
    body {
    background-color: #000000;
    }
    a:link {
    color: #FF6600;
    }
    a:visited {
    color: #FF6600;
    }
    a:hover {
    color: #FF6600;
    }
    a:active {
    color: #FF6600;
    }
    -->
    </style><script language="JavaScript">
    <!-- Begin
    function openpage() {window.focus();
    }
    //  End -->
    </script><style type="text/css">
    input.smallInput{background:#000000;border-bottom-color:#ff6633; border-bottom-width:1px;border-top-width:0px;border-left-width:0px;border-right-width:0px; solid #ff6633; color: #ff6633; FONT-SIZE: 9pt; FONT-STYLE: normal; FONT-VARIANT: normal; FONT-WEIGHT: normal; HEIGHT: 18px; LINE-HEIGHT: normal}
    input.buttonface{BACKGROUND: #000000; border:1 solid #000000; COLOR: #ff6633; FONT-SIZE: 9pt; FONT-STYLE: normal; FONT-VARIANT: normal; font-weight: bold; HEIGHT: 18px; LINE-HEIGHT: normal}
    .style3 {
    color: #FF9900;
    font-size: 12px;
    }
    .style5 {color: #333333}
    .style6 {color: #000000}
    </style>
    </head>
    <body>  <center>
      <b>Web file host    </b><a href="./index.php">Now upload file! </a><br><div align="center">
                        <td width="275" height="60"><form name="form1" enctype="multipart/form-data" method="post" action="upload.php">
                            <input type="file" name="file" size="18" class=smallInput>
                            <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
                            <input type="submit" height=27 width=174 value=upload border=0 name=submit valign="bottom" class="buttonface">
                          <br>
                            </font>
                        </form>
        </td>
              <td width="275" height="50"><FORM onSubmit="openpage()" action='download.php' method=post encType=multipart/form-data>
                Characteristic Code : 
               
                      <INPUT size=26 name="ref"     
    value=
    <?php
    echo $_GET["ref"]?>   
     class="smallInput">
                      <INPUT type="submit" height=27 width=174 value=download border=0 name=submit valign="bottom" class="buttonface"><span class="style6">download</span>
                    </FORM>
                            <span class="style5">
                <script type="text/javascript"></script>
                </span>            </td>
     
    </div>
     </center><br><center>
    </center>
    <br>
    <center>
    The types of files can be uploaded:jpg, gif, png, zip, rar, doc, torrent!The file cannot be exceeded than 10M.
    Following uploading should be prohibited:1.Adult, porny literature and pictures related. 2.Piratic, illegal, virus software.3 Piratic, illegal audio files. 4.And any content which anti national laws. Pls send e-mail to [email protected] if u find the files listed above.
    </center><br></body>
    </html>index.php
    <html>
    <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="."><style type="text/css">
    <!--
    .STYLE2 {
    color: #FF6600;
    font-size: 24px;
    font-weight: bold;
    }
    .STYLE5 {
    color: #FF6600;
    font-size: 16px;
    font-weight: bold;
    }
    body,td,th {
    color: #FF6600;
    }
    body {
    background-color: #000000;
    }
    a:link {
    color: #FF6600;
    }
    a:visited {
    color: #FF6600;
    }
    a:hover {
    color: #FF6600;
    }
    a:active {
    color: #FF6600;
    }
    -->
    </style>
    </head>
    <body>
          
       <span class="STYLE2"><b>Web file host<b></span>
        
      
        
             <div>
               
            
                        <td width="275" height="60"><form name="form1" enctype="multipart/form-data" method="post" action="upload.php">
                            <input type="file" name="file" size="18" >
                            <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
                            <input type="submit" height=27 width=174 value=upload border=0 name=submit valign="bottom">
    <br>
                            </font>
                        </form>
    </td>
                   
             
    </div>
      
            <br>
    <span class="STYLE5"><b>
     <?php
    require 'config.php';
    $text=implode(",",$type);
    echo "Allowed  file type  : ",$text,"  !<br>";
      ?></b>
    </span>
    Powered By <b>Web File host</b>You can download it  <b>here</b>
    The file cannot be exceeded than 10M.<br>
    Following uploading should be prohibited:1.Adult, porny literature and pictures related. 2.Piratic, illegal, virus software.3 Piratic, illegal audio files. 4.And any content which anti national laws. Pls send e-mail to [email protected] if u find the files listed above.
    </body>
    >
    </html>