【发布时间】:2017-02-21 06:32:39
【问题描述】:
HTML:
<form action="" method="post" enctype="multipart/form-data">
Select file to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="password" name="filepassword" id="filepassword">
<input type="submit" value="Upload File" name="submit">
</form>
PHP:
<?php
if(isset($_POST["submit"])) {
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$valueOne =trim($_POST["filepassword"]);
if($valueOne != "1212"){
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
echo "file uploaded successfully !";
}
else{
echo "file is not entered !";
}
}
?>
无论 if(check) 语句中的代码是什么,文件都会被上传
【问题讨论】:
-
如果条件为真,你想上传还是不上传?
-
条件为真我要上传..
-
我认为你应该检查 $_FILES inseat POST
-
在我看来你必须写 if($valueOne == "1212"){ 代替 if($valueOne != "1212"){