【发布时间】: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/ 并且也没有上传。由于我对这个主题不熟悉,所以我不知道如何解决这个问题。
【问题讨论】:
-
你想了解SQL Injection。
-
不要这样写准备好的语句。这让他们毫无意义。
-
文件传输了吗?您需要稍微缩小问题范围。
-
不,文件不传输
标签: php mysql image-upload