未收到图片上传

时间:2017-08-05 08:33:00

标签: php file-upload image-uploading

我收到了img_description,但我的img_name仍为空。

基本的PHP代码

$msg = "";

if(isset($_POST['upload'])) {
$target = "images/".basename($_FILES['image']['name']); // get error here

$image = $_FILES['image']['name']; // get error here
$text = $_POST['text'];

$sql = "INSERT into images (img_name, img_description) values ('$image', '$text')";

$smt = $heidisql->prepare($sql);
$smt->execute();

 if(move_uploaded_file($_FILES['image']['tmp_name'], $target)) { //error here
    $msg = "Image upload sucessfully";
 }else {
   $msg = "Image failed to upload properly";
 }

我的基本表格

 <form method="POST" action="checkout.php" enctype="multipart/form-date">
     <input type="hidden" name="size" value="1000000">
     <div>
       <input type="file" name="image">
     </div>

     <div>
        <textarea name="text" cols="40" rows="4" placeholder="img text decription" ></textarea>
     </div>

      <div>
         <input type="submit" name="upload" value="upload img">
      </div>

   </form>

表:图片,属性 - &gt; img_id,img_name,img_description

  

错误:未定义的索引:图片

2 个答案:

答案 0 :(得分:1)

您的表单标记中的enctype中有拼写错误。

更改

multipart/form-date 

multipart/form-data

答案 1 :(得分:0)

您有写错误 enctype =“multipart / form-date”请改用 enctype =“multipart / form-data”