不在数据库中发布

时间:2014-02-23 06:46:09

标签: php file-upload

我没有收到任何错误。但是我上传的图片没有保存在images/photo/目录中 我在我的数据库中看到它有什么问题吗? 请帮帮我..谢谢。抱歉打扰我只是PHP语言的新手。

这是我的保存代码:

<?php

include('connect.php');

if (isset($_POST['save'])) {
    addpost($_POST['fname'], $_POST['cont'], $_POST['mail'], $_POST['add'], $_POST['description'], $_FILES["image"] ["name"], $_FILES["image"] ["type"], $_FILES["image"] ["size"], $_FILES["image"] ["tmp_name"], $_FILES["image"] ["error"]);
    echo $success = "<script language='javascript' >
    alert('Your Post has been successfuly added!')
    window.location='post.php'
    </script>";
}
?>

这是我在connect.php中的代码:

function addpost($a, $b, $c, $d, $e, $name, $type, $size, $tmp_name, $error) {
    $img = 'images/posts/' . $name;
    mysql_query("INSERT post(p_name,p_contact,p_email,p_address,description,photo,dateadded) values 
('$a','$b','$c','$d','$e','$img',NOW())");

    if ($error > 0) {
        die("Error uploading file! Code $error.");
    } else {
        if ($size > 10000000000) {
            die("Format is not allowed or file size is too big!");
        } else {
            move_uploaded_file($tmp_name, "images/posts/" . $name);
        }
    }
}

1 个答案:

答案 0 :(得分:2)

是的,对于文件上传,您需要在表单中添加enctype='multipart/form-data',以便您的表单应为

<form action="" method="post" enctype="multipart/form-data" onSubmit="return ValidateForm(this);">