doudu8291 2019-04-27 21:37
浏览 61

图片上传不起作用,我也没有收到错误

I am trying to upload an image file to my server using some code I found on the internet but it doesn't work and I can't find out why.

  <form method="post" action="?p=edit-profil&id=<?php echo($user_id); ?>">

        <h2>Profil bearbeiten</h2>
        <hr />

        <h4>Profilbild ändern</h4>
        <p style="margin-top: 5px;">(Zulässige Dateiformate: .png .jpg)</p>
        <input type="hidden" name="size" value="1000000" style="padding: 6px;">
        <div>
          <input type="file" name="image" class="choose-image">
        </div>

        <div>
          <input type="submit" name="add-personal-data" value="Speichern" class="submitbutton">
        </div>

      </form>
// Get image name
    $image = $_FILES['image']['name'];

    // image file directory
    $target = "img/".basename($image);

    $image_insert = 'img/'.$image;

    $image_upload_statement = $pdo->prepare("UPDATE beschreibung SET profilbild = '$image_insert' WHERE user_id = '$user_id'");
    $image_upload_statement->execute();

    if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
      $msg = "Image uploaded successfully";
    }else{
      $msg = "Failed to upload image";
    }

So usually image_insert should be someting like img/picture.png but I only get img/ and there is no upload aswell. Since I am quit new with working with this topic I have no more idea how to fix the problem.

  • 写回答

1条回答 默认 最新

  • douba6365 2019-04-27 22:29
    关注

    Your form tag should have this attribute enctype="multipart/form-data" to be able to send the image to the php file.

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算