【问题标题】:Image upload doesn't work and I also don't get an error图片上传不起作用,我也没有收到错误
【发布时间】:2019-09-16 23:58:10
【问题描述】:

我正在尝试使用我在互联网上找到的一些代码将图像文件上传到我的服务器,但它不起作用,我无法找出原因。

  <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";
    }

所以通常 image_insert 应该类似于 img/picture.png 但我只得到 img/ 并且也没有上传。由于我对这个主题不熟悉,所以我不知道如何解决这个问题。

【问题讨论】:

标签: php mysql image-upload


【解决方案1】:

您的表单标签应具有此属性enctype="multipart/form-data" 才能将图像发送到 php 文件。

【讨论】:

    猜你喜欢
    • 2018-01-28
    • 1970-01-01
    • 1970-01-01
    • 2020-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多