给你一段码作参考
<?
session_start();
require("../../config.php");
require("../../function.php");
require("../../prv.inc");
if($Submit)
  {
     if($name!="" and $file1!="" and $type!="" and $cont!="")
 {
    $date=date("Y")."/".date("m")."/".date("d");
$time=strval($date);
$path="file/";
@mkdir($path);
//$entx1=strchr($file1_name,".");
//$entx2=strchr($file2_name,".");
$filename=$file1_name;
$cpname=$path.$filename;
$file_size=$_FILES['file1']['size'];
if($file1_size<1024) //上载文件大小
           {
              $tpSize=(string)$file1_size."字节";
           }
           elseif($tfile_size<(1024*1024))
           {
              $tpSize=number_format((double)($file1_size/1024),1)."KB";
           }
           else
           {
               $tpSize=number_format((double)($file1_size/(1024*1024)),1)."MB";
            }
$connect=mysql_connect($host,$root,$pas);
        mysql_select_db($db);
$query="select * from book where name='$name'";
$result=mysql_query($query);
if(mysql_num_rows($result))
{echo"<center><font size=\"2\" color=red>该文件名已经存在!</font></center><script>history.back()</script><br>";exit;}
else
{
   if(copy($file1,$cpname))
    {
      echo"<center><font size=\"2\" color=red>文件上传成功!</font></center><script>history.back()</script><br>";
   }
   else
   {
      echo"<center><font size=\"2\" color=red>文件上传失败!</font></center><script>history.back()</script><br>";
   }
}
        $query="insert into book(name,filename,auto,outhome,type,time,outtime,price,number,cont) values('$name','$filename','$auto','$outhome','$type','$time','$outtime','$price','$number','$cont')";
        if(mysql_query($query))
   {
       echo"<center><font size=\"2\" color=red>文件添加成功!</font></center><script>history.back()</script><br>";
   }
   else
   {
       echo"<center><font size=\"2\" color=red>文件添加失败!</font></center><script>history.back()</script><br>";
   }
}
else
{
  echo"<center><font size=\"2\" color=red>您输入的资料不全,请重新输入!</font></center><br>";
}
  }
?>
<html>
<head>
<title>添加文章</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body bgcolor="#F7F7F4">
<form action="" method="post" enctype="multipart/form-data" name="form1">
  <table width="532" border="0" align="center" cellpadding="0" cellspacing="1">
    <tr> 
      <td height="20"><div align="center"><font size="2"><strong>文 件 上 传</strong></font></div></td>
    </tr>
    <tr> 
      <td height="316"><table width="100%" height="350" border="0" cellpadding="0" cellspacing="0">
          <tr> 
            <td height="12" colspan="3"><div align="right"></div></td>
          </tr>
          <tr> 
            <td width="134" height="23"><div align="right"><font size="2">书名:</font></div></td>
            <td width="1"></td>
            <td width="395"><input name="name" type="text" size="35"></td>
          </tr>
          <tr> 
            <td height="24"><div align="right"><font size="2">作者:</font></div></td>
            <td width="1"></td>
            <td><input name="auto" type="text" size="12"></td>
          </tr>
          <tr> 
            <td height="24"><div align="right"><font size="2">出版社:</font></div></td>
            <td width="1" rowspan="2"></td>
            <td><input type="text" name="outhome"></td>
          </tr>
          <tr> 
            <td height="22"><div align="right"><font size="2">出版日期:</font></div></td>
            <td><input name="outtime" type="text" size="16"></td>
          </tr>
          <tr> 
            <td height="26"><div align="right"><font size="2">上传文件:</font></div></td>
            <td width="1"></td>
            <td><input name="file1" type="file" size="20"> <input type="hidden" name="PHP_MAX_SIZE" value="1000000"></td>
          </tr>
          <tr> 
            <td height="22"><div align="right"><font size="2">价格:</font></div></td>
            <td width="1" rowspan="2"></td>
            <td><input name="price" type="text" size="10"></td>
          </tr>
          <tr> 
            <td height="24"><div align="right"><font size="2">数量:</font></div></td>
            <td><input name="number" type="text" size="8"></td>
          </tr>
          <tr> 
            <td height="30"><div align="right"><font size="2">类型:</font></div></td>
            <td width="1"></td>
            <td><select name="type" size="1">
                <option>=请选择文件类型=</option>
                <option value="ASP书籍">ASP书籍</option>
                <option value="PHP书籍">PHP书籍</option>
                <option value="JSP书籍">JSP书籍</option>
                <option value="C#书籍">C#书籍</option>
                <option value="DELPHI书籍">DELPHI书籍</option>
                <option value="ASP.NET书籍">ASP.NET书籍</option>
                <option value="VB书籍">VB书籍</option>
              </select></td>
          </tr>
          <tr> 
            <td height="18"><div align="right"><font size="2">简介:</font></div></td>
            <td width="1"></td>
            <td><textarea name="cont" cols="45" rows="6"></textarea></td>
          </tr>
          <tr> 
            <td height="42" colspan="3"><div align="center"> 
                <input type="submit" name="Submit" value="上传文件">
                &nbsp;&nbsp; 
                <input type="reset" name="Submit2" value="全部重填">
              </div></td>
          </tr>
        </table></td>
    </tr>
  </table>
</form>
</body>
</html>

解决方案 »

  1.   

    Thanks!难道没有别的仁兄会了吗?:(急
      

  2.   

    在php中上传文件比在asp中方便很多
    去下载一个php的用户手册看看把,里面将的很详细拉PHP 能够接受任何来自符合 RFC-1867 标准的浏览器(包括 Netscape Navigator 3 及更高版本,Microsoft Internet Explorer 3 加微软补丁,或者更高版本)上传的文件。PHP 的这种特性使得我们既可以上传文本文件,也可以上传二进制文件。利用 PHP 的认证和文件操作函数,您就可以控制谁有上传的权限,以及在文件上传后进行哪些处理。 相关的设置: 请参阅 php.ini 的 file_uploads、 upload_max_filesize、upload_tmp_dir 以及 post_max_size 设置选项。 请注意 PHP 也支持 PUT 方法的文件上传,Netscape Composer 和 W3C 的 Amaya 客户端使用这种方法。请参阅 PUT 方法支持以获取更多信息。 您可以如下建立一个特殊的表单来支持文件上传: 例子 18-1. 文件上传表单<form enctype="multipart/form-data" action="_URL_" method="POST"> 
    <input type="hidden" name="MAX_FILE_SIZE" value="30000">
    Send this file: <input name="userfile" type="file">
    <input type="submit" value="Send File">
    </form>
     
     
    以上范例中的“_URL_”应该替换成指向一个 PHP 文件的真实 URL。MAX_FILE_SIZE 隐藏域(单位为字节)必须先于文件输入域,其值为接收文件的最大尺寸。同时,要保证您的文件上传表单中要有 enctype="multipart/form-data",否则文件上传将不能工作。 
    警告 
    MAX_FILE_SIZE 的值只是对浏览器的一个建议,实际上它可以被简单的绕过。因此不要把对浏览器的限制寄希望于该值。实际上,PHP 设置中的上传文件最大值,是不会失效的。但是最好还是在表单中加上 MAX_FILE_SIZE,因为它可以避免用户在花时间等待上传大文件之后才发现该文件太大了的麻烦。 
     
    为上传文件定义的变量会根据 PHP 的版本及设置的不同而不同。自动全局变量 $_FILES 从 PHP 4.1.0 版本开始被支持。在这之前,从 4.0.0 版本开始,PHP 支持 $HTTP_POST_FILES 数组。这些数组将包含所有关于您上传的文件的信息,其中,我们推荐您使用 $_FILES。如果 PHP 的设置选项 register_globals 为 on,则相关的变量名将也会存在。从 PHP 4.2.0 版本开始,register_globals 的默认值被设为 off。 以上范例中 $_FILES 数组的内容如下所示。我们假设文件上传字段的名称如上例所示,为 userfile。名称可随意命名。 
    $_FILES['userfile']['name']
    客户端机器文件的原名称。 $_FILES['userfile']['type']
    文件的 MIME 类型,需要浏览器提供该信息的支持,例如“image/gif”。 $_FILES['userfile']['size']
    已上传文件的大小,单位为字节。 $_FILES['userfile']['tmp_name']
    文件被上传后在服务端储存的临时文件名。 $_FILES['userfile']['error']
    和该文件上传相关的错误代码。['error'] 是在 PHP 4.2.0 版本中增加的。 
    注: 在 PHP 4.1.0 版本以前该数组的名称为 $HTTP_POST_FILES,它并不像 $_FILES 一样是自动全局变量。PHP 3 不支持 $HTTP_POST_FILES 数组。 当 php.ini 中的 register_globals 被设置为 on 时,您可以使用更多的变量。例如,$userfile_name 等价于 $_FILES['userfile']['name'],$userfile_type 等价于 $_FILES['userfile']['type'] 等。请记住从 PHP 4.2.0 开始,register_globals 的默认值为 off,因此我们建议您不要依赖于改设置项而使用刚刚提到的那些附加变量。 文件被上传后,默认地会被储存到服务端的默认临时目录中,除非您将 php.ini 中的 upload_tmp_dir 设置为了其它的路径。服务端的默认临时目录可以通过更改 PHP 运行环境的环境变量 TMPDIR 来重新设置,但是在 PHP 脚本内部通过运行 putenv() 函数来设置是不起作用的。该环境变量也可以用来确认其它的操作也是在上传的文件上进行的。 例子 18-2. 使文件上传生效请查阅函数 is_uploaded_file() 和 move_uploaded_file() 以获取进一步的信息。以下范例处理由表单提供的文件上传。 <?php
    // 在 4.1.0 以前的 PHP 中,需要用 $HTTP_POST_FILES 代替 $_FILES。
    // 在 4.0.3 以前的 PHP 中,需要用 copy() 和 is_uploaded_file() 来代替 move_uploaded_file()。$uploaddir = '/var/www/uploads/';
    $uploadfile = $uploaddir. $_FILES['userfile']['name'];
    print "<pre>";
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) {
        print "File is valid, and was successfully uploaded.  Here's some more debugging info:\n";
        print_r($_FILES);
    } else {
        print "Possible file upload attack!  Here's some debugging info:\n";
        print_r($_FILES);
    }?>
     
     
    接受上传文件的 PHP 脚本必须在文件上传后进行判断,来决定接下来要对该文件进行那些操作。例如,您可以通过 $_FILES['userfile']['size'] 变量来忽略尺寸太大或太小的文件,也可以通过 $_FILES['userfile']['type'] 变量来过滤文件类型和某种标准不相符合的文件。在 PHP 4.2.0 以上版本,您还可以通过 $_FILES['userfile']['error'] 变量来根据不同的错误代码来做相关的判断。不管做何种的判断,您必须将该文件从临时目录中删除,要么将其移动到其它的地方。 如果该文件没有被移动到其它地方也没有被改名,则该文件将在表单请求结束时被删除。 
      

  3.   

    看我的上传文件函数怎么样呀:<? //上载文件
    function UploadFile($srcName,$Size,$destName,$destPath)
    {
    echo $srcName."<hr>";
    echo $destPath.$destName."<hr>";

    if (!is_uploaded_file($srcName)) {
    $Result['result']="FAILDED";
    $Result['info']="the file is not a upload file !";
    return $Result;
    }
    //检查参数的合法性
    if (!is_dir($destPath)){
    if (!mkdir($destPath,0777)){
    $Result['result']="FAILDED";
    $Result['info']="the destination directory is not exist!";
    return $Result;
    }
    }
    if ( 1024000 < $Size ){
    $Result['result']="FAILDED";
    $Result['info']="file is must be less than 1 MB(1024000 Bytes)!";
    return $Result;
    }
    if ("" == $destPath){
    $Result['result']="FAILDED";
    $Result['info']="The destination of path is invalid!";
    return $Result;
    }
    //输入了上载文件,但文件未上载成功
    if ( ($srcName == "none" || $srcName == "" ) and $destName!=""){
    $Result['result']="FAILDED";
    $Result['info']="The file <font color=red>".$destName."</font> 's uploaded failed !";
    return $Result;
    }
    //未输入上载文件
    if (($srcName == "none" || $srcName == "" ) and $destName==""){
    $Result['result']="FAILDED";
    $Result['info']="no uploaded file!";
    return $Result;
    }
    //文件重名处理
    $i = 1;
    while (file_exists($destPath.$destName)){
    $destName = "$i".$destName;
    $i++;
    }
    //文件上载成功后,将文件拷贝到目的地
    if (!move_uploaded_file($srcName,$destPath.$destName)){
    $Result['result']="FAILDED";
    $Result['info']="the file <font color=red>".$destName."</font>'s uploaded failed!";
    return $Result;
    } //返回成功信息
    $Result['result']='SUCCESS';
    $Result['info']=$destName;
    echo $destName;
    return $Result;
    }
    ?>
      

  4.   

    服务器端的 asp2php可以进行asp到php的转换
      

  5.   

    <%  
    Function GetAllFiles()
    Dim oFS, oFolder, oFile
    Set oFS = Server.CreateObject("Scripting.FileSystemObject")
    If Not oFS.FolderExists(FILE_FOLDER) Then Exit Sub
    Set oFolder = oFS.getFolder(FILE_FOLDER)

    Dim intCounter
    Dim FileArray()

    intCounter = 0
    ReDim Preserve FileArray(oFolder.Files.Count, 5)

    For Each oFile in oFolder.Files
    strFileName = oFile.Name
    strFileType = oFile.Type
    strFileSize = oFile.Size
    strFilePath = oFile.Path
    strFileDtMod = oFile.DateLastModified

    FileArray(intCounter, 0) = strFileName
    FileArray(intCounter, 1) = "<A HREF=" & Chr(34) & "startDownload.asp?File=" _
    & strFilePath & "&Name=" & strFileName & "&Size=" & strFileSize & Chr(34) _
    & " onMouseOver=" & Chr(34) & "self.status='" & strFileName & "'; return true;" & Chr(34) _
    & " onMouseOut=" & Chr(34) & "self.status=''; return true;" & Chr(34) & ">" & strFileName & "</A>"
    FileArray(intCounter, 2) = strFileType
    FileArray(intCounter, 3) = strFileSize
    FileArray(intCounter, 4) = strFilePath
    FileArray(intCounter, 5) = strFileDtMod

    intCounter = (intCounter + 1)
    Next

    EchoB("<B>" & oFolder.Files.Count & " Files Available to Download</B>")

    intRows = uBound(FileArray, 1)
    intCols = uBound(FileArray, 2)

    For x = 0 To intRows -1
    Echo("<TR>")
    For z = 0 To intCols
    If z > 0  Then
    BuildTableCol(FileArray(x, z))
        ELSE
            Echo("<TD><INPUT TYPE=CHECKBOX NAME=downloadedfiles VALUE='" & FileArray(x, 4) & "'></TD>")
    End IF
    Next
    Echo("</TR>")
    Next


    Cleanup oFile
    Cleanup oFolder
    Cleanup oFS
    End FunctionFunction Echo(str)
    Echo = Response.Write(str & vbCrLf)
    End FunctionFunction EchoB(str)
    EchoB = Response.Write(str & "<BR>" & vbCrLf)
    End FunctionFunction Cleanup(obj)
    IF isObject(obj) Then
    Set obj = Nothing
    End IF
    End FunctionFunction StripFileName(strFile)
    StripFileName = Left(strFile, inStrRev(strFile, "\"))
    End FunctionFunction BuildTableCol(strData)
    Echo("<TD CLASS=DataCol>" & strData & "</TD>")
    End Function
    Function BuildTableRow(arrData)
    Dim intCols
    intCols = uBound(arrData)
    For y = 0 To intCols
    Echo("<TD CLASS=DataCol>" & arrData(y) & "</TD>")
    Next
    End Function%>
    这段ASP代码转过来实现不了啊,大家帮帮忙吧,急