Your form is missing enctype="multipart/form-data"
change it to:
<form method = "post" enctype="multipart/form-data" action = "<?php echo $_SERVER['PHP_SELF']; ?>">
which is required when uploading files.
Pergunta
I cannot see what I am missing.. I am trying to let users upload a file for a picture post on a social media website, I have already made it so they can choose a profile picture and that works fine, but for some reason this does not work.
<div class = "midCol"><?php
//show post box
?><form method = "post" action = "<?php echo $_SERVER['PHP_SELF']; ?>">
<div class = "box" style = "width:500px;">
<textarea class = "poster" rows="5" cols="50" id = "area" name = "area" value = "area"
placeholder = "What's on your mind?"></textarea><br/>
<input type = "file" id = "picture" name = "picture"/><br/>
<input type = "Submit" value = "Post" name = "post"/><br/>
</div>
</form><?php
and here is the PHP in the same script:
//submit post
if (isset($_POST['post']))
{
$postContent = mysqli_real_escape_string($dbc, $_POST['area']);
$newPost_query = "INSERT INTO posts (uid, post, uname) VALUES ('$uid', '$postContent', '$uname')";
$postPicture_query = "UPDATE posts SET picture = postId";
$postContent_exc = mysqli_query($dbc, $newPost_query);
//move uploaded file
echo $_FILES['picture']['tmp_name'];
$pic = mysqli_insert_id($dbc);
move_uploaded_file($_FILES['picture']['tmp_name'], 'images/posts/' . $pic);
mysqli_query($dbc, $postPicture_query);
}
It's a little messy because I've been changing it left and right and I'll clean it up later, but does anyone see what I am doing wrong??
Solução
Your form is missing enctype="multipart/form-data"
change it to:
<form method = "post" enctype="multipart/form-data" action = "<?php echo $_SERVER['PHP_SELF']; ?>">
which is required when uploading files.