将图片上传到我的用户目录时,他们会很好地进入我的数据库,但他们没有转移到我的服务器,所以他们可以在获取请求上显示。
我查看了所有帖子并实际复制了一个,但它仍然无法正常工作。
这是我的代码:
if(isset($_POST['sub'])) {
$target_path = "user_uploads/";
$target_path = $target_path . basename( $_FILES['img_upload']['name']);
$post = nl2br(addslashes($_POST['content']));
if (($_FILES["img_upload"]["type"] == "image/gif")
|| ($_FILES["img_upload"]["type"] == "image/jpeg")
|| ($_FILES["img_upload"]["type"] == "image/jpg")
|| ($_FILES["img_upload"]["type"] == "image/pjpeg")
|| ($_FILES["img_upload"]["type"] == "image/x-png")
|| ($_FILES["img_upload"]["type"] == "image/png")
&& ($_FILES["img_upload"]["size"] < 2000000))
{
if ($_FILES["img_upload"]["error"] > 0)
{
echo "Return Code: " . $_FILES["img_upload"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["img_upload"]["name"] . "<br>";
echo "Type: " . $_FILES["img_upload"]["type"] . "<br>";
echo "Size: " . ($_FILES["img_upload"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["img_upload"]["tmp_name"] . "<br>";
if (file_exists("user_uploads/" . $_FILES["uploadedfile"]["tmp_name"]))
{
echo $_FILES["img_upload"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES['img_upload']['tmp_name'], $target_path);
echo "The file ". basename( $_FILES['img_upload']['name']).
" has been uploaded";
}
}
}
else
{
echo "Invalid file";
}
$insert = "INSERT INTO posts (user_id, post_content, post_image, img_type, img_size, post_date) VALUES ('$user_id', '$post','$target_path', '$img_type', '$img_size', NOW())";
if ($con->query($insert) === TRUE) {
echo "<script>window.open('home.php?=$user_name','_self')</script>";
}