我正在使用这个 php 照片上传脚本将图像存储到我的数据库中。
我的数据库有三列:'user_id''name''image'
一切正常。图片已上传,但目前它不存储 user_id,我想尝试制作它,以便当用户点击上传时,它使用他们的会话 ID 来存储他们的 user_id。
通过将这两个函数添加到原始 mysql 查询中,我尝试了一下:
(user_id, image, name)
'".$_SESSION['user_id']."',
<html>
<head>
<title>Upload Image</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<input type="file" name="image">
<input type="submit" value="Upload">
</form>
<?php
include("includes/_config/connection.php");
// file properties
$file = $_FILES['image']['tmp_name'];
if (!isset($file))
echo "";
else {
$image = addslashes (file_get_contents ($_FILES['image']['tmp_name']));
$image_name = addslashes ($_FILES['image']['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if ($image_size == FALSE)
echo "That's not an image.";
else {
if (!$insert = mysql_query ("INSERT INTO ptb_img_uploads (user_id, image, name) VALUES ('', '".$_SESSION['user_id']."', '$image_name','$image')"))
echo "There was a problem sending the image.";
else
echo "Your image was successfully uploaded.";
}
}
?>
</body>
</html>