這是一個php代碼。它不工作。存儲在圖像名稱的db,而不是圖像。 我serached這個問題,但我無法找到一個解決方案。我試過file_get_contents()但沒有工作。我不是如果是服務器或代碼的問題。
<?php
$msg="";
if(isset($_POST['submit'])){
session_start();
$target_dir="uploads/";
$target_file=$target_dir . basename($_FILES["fileToUpload"]["name"]);
include 'dbh.php';
$image=$_FILES['fileToUpload']['name'];
$image_tmp=$_FILES['fileToUpload']['tmp_name'];
$id=$_SESSION['id'];
$sql="UPDATE user SET image='$image' WHERE id='$id'";
mysqli_query($conn,$sql) or Die("ERROR:" .mysqli_error($conn));
if(move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_file)){
$msg="Image uploaded successfully";
}
else{
$msg="There was a problem uploading image";
}
}
?>
<form action="user_photo.php" method="post" enctype="multipart/form-data" target="iframe">
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" name="submit" value="Ngarko Foto">
</form>
您是否真的想將圖像存儲到數據庫中,而不僅僅是'uploads'目錄中文件的名稱? – Barmar