段:
$connect = //connect to db;
$db = $connect->prepare("SELECT profilepicture FROM user WHERE uname = $uname");
$db->execute();
$db->bind_result($img);
...
echo $img;
信息:
- 我将image.bin
存储在db
中的表的列中
- 在十六进制编辑器中打开image.bin
显示十六进制代码(文件标题表示它是PNG文件)
- echo $img
无法输出图片
问题: - 如何输出存储在db?
中的图像答案 0 :(得分:0)
表格
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
这是您上传文件的方式
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)){
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
$img = basename($_FILES["fileToUpload"]["name"]);
Your insert query
$db = $connect->prepare("UPDATE user SET profilepicture =? WHERE uname = ?");
$db->bind_param("si",$img,$uname);
$db->execute();
取自w3schools