我正在上传图片,但即使我明确选择了一个文件,isset()
也会返回false
。这是我的代码。
<form id="form1" name="form1" method="POST" enctype="multipart/form-data" action="addroom.php">
<p>Upload pictures:</p>
<p>Bed:</p>
<input type="file" name="image1"/>
<p>Comfort room</p>
<input type="file" name="image2"/>
<p>Living room:</p>
<input type="file" name="image3"/>
<input type="submit" id="add" name="add" value="Add Room Category"/>
</form>
<?php
if(isset($_POST['image1']))
$file1=$_FILES['image1']['name'];
else
echo "image not selected";
答案 0 :(得分:2)
上传的文件存储在$_FILES
中。 $_POST['image1']
不存在,因为它是文件,而不是文本(或其他)字段。
您想要使用:
if(isset($_POST['add']))
或
if(isset($_FILES['image1']))
答案 1 :(得分:0)
试试这个
if(isset($_FILES["image1"]["name"])){...}