我有这个:
<input type="file" name="image">
if(isset($_POST['submit']))
{
if(isset($_FILES['image']['name']))
{
$image=$_FILES['image']['name'];
}
else
{
$error= 'Error: no image was set ';
}
基本上,它告诉我图像,名称不存在不存在..为什么?
{
$error= 'Error: no image was set ';
}
答案 0 :(得分:4)
您的FORM是否有enctype =“multipart / form-data”属性?
<form name="xyz" action="myscript.php" enctype="multipart/form-data">
...
</form>
EncType属性用于告诉浏览器如何将数据发布到服务器。如果不使用多部分mime类型,则无法正确地将数据发送到服务器。
Multipart看起来像这样:
boundary:xyz
====xyz====
name: field1
content-type: text/plain
content-lenght: 10
1234567890
====xyz====
name: field2
content-type: text/plain
content-lenght: 10
1234567890
====xyz====
name: field3
content-type: text/plain
content-lenght: 10
1234567890
你不必自己发送,只需设置enctype,并为你完成所有魔法。