图片未上传(未找到输入名称)

Image not uploading (input name not found)

我有一个使用 BLOB 的图片上传代码。 我收到此错误。

Undefined index: image in C:\wamp\www\sj\ad_posted.php on line 19

HTML:

    <form action="ad_posted.php" method="post">
<table width="700" border="0" cellspacing="10">
  <tr>
    <td>COMPANY NAME:</td>
    <td align="justify"><input name="ad_name" type="text" size="40" maxlength="25" /></td>
  </tr>
    <tr>
    <td>LOCATION:</td>    
    <td align="justify"><input name="ad_location" type="text" size="40" maxlength="25" /></td>
</td>
  </tr>
    <tr>
    <td>CONTACT NO:</td>    
    <td align="justify"><input name="ad_contact" type="text" size="40" maxlength="25" /></td>
</td>
  </tr>
    <tr>
    <td>IMAGE:</td>
    <td><input name="image" type="file" style="height:30px;"/></td>
  </tr>
    <tr>
    <td colspan="2"><input type="submit" name="submit" value="Submit" /></td>
  </tr>
</table>
</form>

这是上传图片的 PHP 代码:

$file = $_FILES['image']['tmp_name'];

if(!isset($file))
{
    echo "Please select an image";
}

else 
{ 
    $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));   
    $image_name = addslashes($_FILES['image']['name']);
    $image_size = getimagesize($_FILES['image']['tmp_name']);
    if($image_size == FALSE)
    echo "Thats not image";

    else 
    {
        $sql = "Insert into advertisement (ad_name,ad_location,ad_contact,ad_category,ad_image) values  ('$name','$location','$contact',$category,'$image')";
        $result = mysqli_query($conn,$sql) or mysqli_error($conn);
    }
}

PS:此代码在我的其他站点上运行正常。我复制了相同的代码,但没有对我的新项目进行任何更改,但我收到了这个错误!虽然我确实看到任何问题,但在它显示的错误中。

根据您的修改 <form action="ad_posted.php" method="post">

好吧,你的表单中缺少 enctype="multipart/form-data"

处理文件时需要。

参考文献: