uploadfile.php:<?
if($upfile)
{
    if($file1_size>3000000)
        exit("上传文件的大小限制在3M内!");
    if(copy($file1,"upload/$file1_name"))
        echo "上传成功!";
    else
        echo "上传失败!";
}
else
{
?>
    <html> 
    <head> 
    <title>文件上传</title>
    </head> 
    <body> 
    <table> 
        <form enctype="multipart/form-data" action=<? echo $PHP_SELF; ?> method="post"> 
        <tr>
            <td>选择上传文件</td>
            <td><input name="file1" type="file"></td>
        </tr>
        <tr>
            <td colspan="2"><input name="upfile" value="上传" type="submit"></td>
        </tr> 
        </form>
    </table> 
    </body> 
    </html>
<?
}
?>

解决方案 »

  1.   

    现在的问题是如果附件过大,根本得不到文件的大小,$file1_size=0
      

  2.   

    先把php.ini里的upload_max_filesize设置稍微大一点的值
    如upload_max_filesize = 5M
      

  3.   

    is_uploaded_file
    (PHP 3>= 3.0.17, PHP 4 >= 4.0.3)is_uploaded_file -- Tells whether the file was uploaded via HTTP POST
    Description
    bool is_uploaded_file ( string filename)
    Returns TRUE if the file named by filename was uploaded via HTTP POST. This is useful to help ensure that a malicious user hasn't tried to trick the script into working on files upon which it should not be working--for instance, /etc/passwd. This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system. 
    $_FILES['userfile']['name']
    客户端机器文件的原名称。 $_FILES['userfile']['type']
    文件的 MIME 类型,需要浏览器提供该信息的支持,例如“image/gif”。 $_FILES['userfile']['size']
    已上传文件的大小,单位为字节。 $_FILES['userfile']['tmp_name']
    文件被上传后在服务端储存的临时文件名。 $_FILES['userfile']['error']
      

  4.   

    可以先检查文件的大小吗?在上传之前。
    用 filesize  超过上传限制就不执行上传动作!
      

  5.   

    $file=$HTTP_POST_FILES["file"];
    $file_size=$file['size'];
    得到字节数
    再换算成k就行了
      

  6.   

    客户端无法得到文件大小!只有上传后才能得到大小!鉴于此种情况建议将php.ini里的upload_max_filesize 设置足够大的值,然后用上面的方法获取文件大小,并加以控制!
    如果文件超出系统设置的最大值,可用下面的方法控制!
    if($file1_size>1000000 || $file1_size==0)
            exit("上传文件的大小限制在1M内!");
      

  7.   

    用FTP函数,调整页面的执行时间