duanjin9035 2015-04-01 07:37
浏览 30
已采纳

PHP使用for或语句给出错误

I am trying to write validation code when user upload file. Condition : file size maximum 500kb and only doc and docx file I use this code but not working properly.

I want to give visitor permission to upload cv in my website, with server side validation (PHP).

<html>
<head>
<title>Validation</title>
</head>

<body>
<?php
$msg = "";
$msgsize = "";
if(isset($_POST['add']))
{   

$filename=$_FILES['resume']['name'];
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
    $uname = $_POST['uname'];
    $uemail = $_POST['uemail'];
    $uphone = $_POST['uphone'];
    $resume = $_FILES['resume']['name'];

    if($uname=="" || $uemail=="" || $uphone=="" || $resume=="")
    {
        $msg = "Please fill in all required fields!";
    }
    else if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$uemail)) 
    {
        $msg = "Invalid email format";

    }


    //echo $ext;
    else if($ext != '.doc' or $ext != '.docx')
    {       
        $msg = "Type Error";
    }
    else if($_FILES["resume"]["size"]>500000)
    {
        $msg = "Size error". $_FILES["resume"]["size"] . "Only 500KB Resume Allowed";
    }   
    else 
    {
        $msg = "GOOD";
    }
}
?>
<div style="background:#FF6600; padding:10px;"><?php echo $msg . $msgsize; ?></div>
<form id="form1" enctype="multipart/form-data" name="form1" method="post" action="<?php $_PHP_SELF ?>">
<table width="700" border="1">
  <tr>
    <td width="178">Name</td>
    <td width="506"><input name="uname" type="text" /></td>
  </tr>
  <tr>
    <td>Email</td>
    <td><input name="uemail" type="text" /></td>
  </tr>
  <tr>
    <td>Phone</td>
    <td><input name="uphone" type="text" /></td>
  </tr>
  <tr>
    <td>Resume</td>
    <td><input name="resume" value="60000000" id="resume" type="file" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>      
        <input type="submit" name="add" id="add" value="Add">
    </td>
  </tr>
</table>
 </form>
</body>
</html>
  • 写回答

3条回答 默认 最新

  • douye6812 2015-04-01 07:59
    关注

    here you need to change

    else if($ext != '.doc' AND $ext != '.docx') {     //use AND instead of OR
        $msg = "Type Error";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!