| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 784 人关注过本帖
标题:请教文件上传错误的原因
只看楼主 加入收藏
xufan
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:232
专家分:804
注 册:2008-10-20
结帖率:88.89%
收藏
已结贴  问题点数:0 回复次数:4 
请教文件上传错误的原因
程序代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. xmlns="http://www. http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP文件上传</title>
<script type="text/javascript">
function checkForm()
{
    if (form1.userfile.value="")
    {
        alert("请选择要上传的文件。");
        form1.userfile.focus();
        return false;
    }
}
</script>
</head>

<body>
<?php
if (!isset($_POST['submit'])){?>


<form name="fomr1" action="#" method="post" enctype="multipart/form-data" onsubmit="return checkForm()">
<table width="396" height="108" border="1" cellpadding="0" cellspacing="0" rules="none">
  <tr>
    <td colspan="2" bgcolor="#999999">文件上传</td>
  </tr>
  <tr>
    <td width="97">选择文件:</td>
    <td width="319"><input name="userfile" type="file" id="userfile" /></td>
  </tr>
  <tr>
    <td><input name="MAX_FILE_SIZE" type="hidden" value="5242880" /></td>
    <td><input type="submit" name="submit" value="执行文件上传" />&nbsp;&nbsp;<input type="reset" name="reset" value="重置" /></td>
  </tr>
</table>

<?php }else {
$uploaddir="../uploads/";
if (!file_exists($uploaddir)) mkdir($uploaddir);
$uploadfile=$uploaddir.basename($_FILES["userfile"]["name"]);
if (move_uploaded_file($_FILES["userfile"]["tmp_name"],$uploadfile))
{
    printf("<b>上传文件信息</b>\n");
    printf("<ul>");
    printf("<li>文件名:  %S</li>\n",$_FILES["userfile"]["name"]);
    printf("<li>文件类型:  %S</li>\n",$_FILES["userfile"]["type"]);
    printf("<li>文件大小:  %S</li>\n",$_FILES["userfile"]["size"]);
    printf("<li>文件名:  %S</li>\n",$_FILES["userfile"]["name"]);
    printf("<p>文件上传成功</p>\n");
    printf("<a href=\"%s\">返回</a>\n",basename($PHP_SELF));
   
}
else
{
    printf("<p>文件未能上传成功</p>");
}
?>
</body>
</html>
错误提示:Parse error: syntax error, unexpected $end in F:\AppServ\www\MyServer\chap03.php on line 62
怎么改呢?在线等待师傅教我
搜索更多相关主题的帖子: 文件 
2010-05-09 21:02
cnenc
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:35
帖 子:2913
专家分:514
注 册:2007-1-29
收藏
得分:0 
你不应该把 if 语句拆成两段.


更更不应该把 { } 拆开.
2010-05-09 23:18
xufan
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:232
专家分:804
注 册:2008-10-20
收藏
得分:0 
回复 2楼 cnenc
那该如何改正呢?请教哦

~~~~~~我的明天我知道~~~。
2010-05-10 12:45
cnenc
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:35
帖 子:2913
专家分:514
注 册:2007-1-29
收藏
得分:0 
不好意思, 明天忘记看了.
你是在最后面少了一个 "}", 导致失败
2010-05-10 14:59
cnenc
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:35
帖 子:2913
专家分:514
注 册:2007-1-29
收藏
得分:20 
程序代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. xmlns="http://www. http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP文件上传</title>
<script type="text/javascript">
function checkForm()
{
    if (form1.userfile.value="")
    {
        alert("请选择要上传的文件。");
        form1.userfile.focus();
        return false;
    }
}
</script>
</head>
<body>
<?php
if (!isset($_POST['submit']))
{
    print <<<EOT
    <form name="fomr1" action="#" method="post" enctype="multipart/form-data" onsubmit="return checkForm()">
    <table width="396" height="108" border="1" cellpadding="0" cellspacing="0" rules="none">
      <tr>
        <td colspan="2" bgcolor="#999999">文件上传</td>
      </tr>
      <tr>
        <td width="97">选择文件:</td>
        <td width="319"><input name="userfile" type="file" id="userfile" /></td>
      </tr>
      <tr>
        <td><input name="MAX_FILE_SIZE" type="hidden" value="5242880" /></td>
        <td><input type="submit" name="submit" value="执行文件上传" />&nbsp;&nbsp;<input type="reset" name="reset" value="重置" /></td>
      </tr>
    </table>
    </form>
EOT;
}
else
{
    $uploaddir="../uploads/";
    if (!file_exists($uploaddir)) mkdir($uploaddir);
    $uploadfile=$uploaddir.basename($_FILES["userfile"]["name"]);
    if (move_uploaded_file($_FILES["userfile"]["tmp_name"],$uploadfile))
    {
        echo "<b>上传文件信息</b>\n";
        echo "<ul>";
        echo "<li>文件名:".$_FILES["userfile"]["name"] ."</li>\n" ;
        echo "<li>文件类型:".$_FILES["userfile"]["type"] ."</li>\n" ;
        echo "<li>文件大小:".$_FILES["userfile"]["size"] ."</li>\n" ;
        echo "<li>文件名:".$_FILES["userfile"]["name"] ."</li>\n" ;
        echo "<p>文件上传成功</p>\n" ;
        echo "<a href=\"".$_SERVER['SCRIPT_NAME']."\">返回</a>\n";
    }
    else
    {
        printf("<p>文件未能上传成功</p>");
    }
}
?>
</body>
</html>

2010-05-10 14:59
快速回复:请教文件上传错误的原因
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019054 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved