HTML将if语句添加到<option> <select> </select> </option>

时间:2012-05-08 23:54:57

标签: php html

我有一个图片上传器,我正在尝试让网站显示上传文件时选择了哪种类型的选项。我稍后会添加此功能以连接到数据库中的不同表,但是现在我只想打印出已选择的选项。

这是我的上传内容。 HTML:

<body>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="400000" />
Choose a file to upload:
<br />
<br />
<input name="uploadedfile" type="file" />
<br />
<select name = "uploadType">
<option value="Picture">Picture</option>
<option value="Video">Video</option>
<option value="Fact">Fact</option>
</select>
<br />
<br />
<input type="submit" value="Upload File" />
</form>
</body>

这是我的上传者。 PHP:     

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
" has been uploaded";

if (uploadType == "Picture"){
echo "\nYou have uploaded a picture.";

} if (uploadType == "Video"){
echo "\nYou have uploaded a video.";
} if (uploadType == "Fact"){
echo "\nYou have uploaded a fact.";
} else{
echo "\nuploadType fail!";
}

} else{
    echo "There was an error uploading the file, please try again!";
}

每次我尝试上传时,都会出现“uploadType失败!”信息。我做错了什么?

非常感谢任何帮助!

非常感谢你!

3 个答案:

答案 0 :(得分:2)

$uploadType = $_POST["uploadType"];

然后在if语句中使用$uploadType。 PHP中的变量总是以美元符号开头。

此外,请将else if用于其他条件。

答案 1 :(得分:1)

你缺少两个'其他'陈述 - 在视频之前和'if'陈述之前。

答案 2 :(得分:0)

uploadType在这里被用作常数。尝试将uploadType替换为$_POST['uploadType']