上传图像到数据库不起作用

时间:2017-05-27 18:51:48

标签: php html css database mysqli

我在html中创建一个表单,它将运行php文件并在数据库中上传图像和文本。我的HTML完全指向php但上传过程不起作用。每次按下提交按钮,php文件显示无法正常工作

我的Html代码:

<form name="f1" method="post" action="php/Savent.php" 
 enctype="application/x-www-form-urlencoded">
    <fieldset>
        <legend name = "addev" align="right"><b>Detail</b></legend>
        <table width="100%">
            <tr align="center">
                <th>Choose Image : </th>
                <td><input type="file" name="image"/></td>
            </tr>
            <tr>
                <td colspan="2"><br/></td>
            </tr>
            <tr align="center">
                <th>Description : </th>
                <td><textarea name="desc" rows="6" cols="30" style="resize: 
                     none"></textarea></td>
            </tr>
            <tr>
                <td colspan="2"><br/></td>
            </tr>
            <tr align="center">
                <td colspan="2" align="center"><input name="submit" 
                  type="submit" value="Submit"/> <input type="reset" 
                  value="Reset"/></td>
            </tr>
            <tr>
                <td colspan="2"><br/></td>
            </tr>
        </table>

Php代码:

 <?php

  if(isset($_POST["submit"])){
    mysqli_connect("sql303.unaux.com","unaux_20153623","testin");
    mysqli_select_db("unaux_20153623_dummy");

    $imageName = mysqli_real_escape_string($_FILES["image"]["name"]);
    $imageData = 
    mysqli_real_escape_string(file_get_contents($_FILES["image"]
    ["tmp_name"]));
    $imageType = mysqli_real_escape_string($_FILES["image"]["type"]);
    $desc = mysqli_real_escape_string($_POST["desc"]);

    if (substr($imageType,0,5) == "image"){
        echo "Working";
    mysqli_query("INSERT INTO 'events' 
    VALUES('','$imageName','$imageData','$desc')");
    echo "Saved Succesfully";
    }
    else{
    echo "Not Working";
    }
   }

   ?>

1 个答案:

答案 0 :(得分:0)

添加此enctype =&#34; multipart / form-data&#34;在表单元素中,您使用了错误的enctype