move_uploaded_file()错误。获得警告,无法移动文件

时间:2016-08-31 07:41:16

标签: php mysql database

当我所做的一切都是将文件上传到数据库中时,我的代码工作得很好。但当我试图将它也存储在文件夹中时,我收到了警告:

Warning: move_uploaded_file(): Unable to move 'F:\xammp\xammp\tmp\php34C9.tmp' to 'uploads/' in F:\xammp\xammp\htdocs\custom-cms-praktis\main.php on line 47

我想我错过了一些重要但我无法弄清楚-_-这是我的代码:

<?php
$server = "localhost";
$user = "root";
$password = "";
$db = "cms_development";

$conn = new mysqli($server,$user,$password,$db);


if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
if (isset($_POST['username']) && isset($_POST['submit'])) {

    $fileName = $_FILES['file']['name'];
    $tmp_name = $_FILES['file']['tmp_name'];
    $fileSize = $_FILES['file']['size'];
    $fileType = $_FILES['file']['type'];
    $author = $_POST['username'];
    $email = $_POST['email'];

    $fp = fopen($tmp_name, 'r');
    $content = fread($fp, fileSize($tmp_name));
    $content = addslashes($content);
    fclose($fp);

    if (!get_magic_quotes_gpc()) {
        $fileName = addslashes($fileName);
    }

    if (move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/")) {

        $query = "INSERT INTO upload (name, size, type, content, author, email ) ".
            "VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$author', '$email')";

        mysql_query($query) or die('Error, Bad Query');

    } else {

        echo "Sorry, there was an error uploading your file.";

    }

}
?>

    <form method="post" action="" enctype="multipart/form-data">
        <input type="text" name="username" value="" placeholder="Name">
        <input type="text" name="email" value="" placeholder="Email">
        <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
        <input type="file" name="file">
        <input type="submit" value="Submit" name="submit">
    </form>
</div>

我在当地工作

1 个答案:

答案 0 :(得分:-1)

检查文件夹“uploads /”是否存在

如果您不知道您正在使用哪个目录 echo getcwd(); 打印它

我认为它应该在那个目录中:F:\ xammp \ xammp \ htdocs \ custom-cms-praktis \ uploads