移动上传的文件

时间:2014-05-05 20:28:51

标签: php html file-upload mysqli

我看不到我错过了什么..我试图让用户上传一个社交媒体网站上的图片文件的文件,我已经做了所以他们可以选择个人资料图片并且工作正常,但是某些原因这不起作用。

<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

这是同一个脚本中的PHP:

 //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);

}

这有点乱,因为我一直在左右改变它,我会在以后清理它,但是有人看到我做错了吗?

1 个答案:

答案 0 :(得分:3)

您的表单遗失enctype="multipart/form-data"

将其更改为:

<form method = "post" enctype="multipart/form-data" action = "<?php echo $_SERVER['PHP_SELF']; ?>">
上传文件时需要