无法将BLOB中的文件上传到数据库,PHP中的目录问题

时间:2017-01-02 02:15:52

标签: php mysql

我很难插入值,因为blob类型总是为空,而另一种方法无法将图像插入文件夹中。请你们展示出路。谢谢!此代码用于将图像保存在文件夹中,然后使用要显示的名称访问它,但不将照片保存到文件夹中。我在这里编辑并包含了包含JavaScript和css的表单。它看起来有些混乱,但我是初学者。感谢。

<?php
include("../views/post_form.php");
require("../includes/include.php");
require("../includes/sess_n.php"); 

if ($_SERVER["REQUEST_METHOD"]== "POST")
{
    $usertext = $_POST["usertext"];
    $image = $_FILES['image']['name'];
    $talent =$_POST["talenttype"];

    if(empty($usertext) || empty($image)|| empty($talent))
    {
        die();
    }

    $id = $_SESSION["id"];
    $folder ="images/".basename($_FILES['image']['name']);
    move_uploaded_file($_FILES['image']['tmp_name'],$folder) ;
    $query = mysqli_query($link,"SELECT * FROM `upload` WHERE id = '$id'");
    $upload = mysqli_query($link,"INSERT INTO `upload` (description,image,talent,folder) VALUES('$usertext','$image','$talent','$folder ')");
}
?>

要显示,我希望将照片保存到文件夹,而不是保存。我使用blob方法不插入数据库。

<?php
include("../views/feeds_form.php");
require("../includes/include.php");
require("../includes/sess_n.php");

$query = mysqli_query($link,"SELECT  * FROM `upload` ");

if ($query === false)
{
    die();
}

echo '<table>';
while ($run = mysqli_fetch_assoc($query)) 
{
    echo '<tr>';
    echo '<td>';?> <img src =" <?php echo $run["image"]; ?>" height=100 width=100> <?php echo '<td>';
    echo '<td>'; echo $run["description"]; echo '<td>';  echo $run["folder"];echo '<td>';
    echo '</tr>';
}
echo '</table>';
?>

这里的表格。

<?php
include("../public/header.php");
?>

<div><title>post</title></div>
<style>
.form-inline
{
    text-align: center;
    margin-bottom: 50px;
}
</style>
<script type="text/javascript">
function validate(){
    var usertext = document.getElementById("usertext");
    var talent = document.getElementById("talenttype");
    var image = document.getElementById("image");

    if (usertext.value === "" && talent.value === "" && image.value ==="") 
    {
        alert("Field Must Not be Empty");
    }
}
</script>

<form class="form-inline"  method ="POST" action ="post.php" enctype="multipart/form-data" onsubmit= "return validate();">
    <div class="form-group">
        <label class="sr-only" for="exampleInputEmail3"> </label>
        <textarea class="form-control" id = "usertext" name ="usertext" rows="5" placeholder="Describe Person Here"></textarea> <br><hr>
        <label class="sr-only" for="exampleInputEmail3"></label><br>
        <div class="form-group">
            <label for="exampleInputPassword1"></label>
            <input type="file" class="form-control" id = "image" id="exampleInputPassword1" name="image" placeholder="image">
        </div> <br><br><br> <hr>
        <div class="form-group">
            <label for="exampleInputPassword1"></label>
            <input type="text" class="form-control" id = "talenttype" id="exampleInputPassword1" name = "talenttype" placeholder="Talent-Type"><br><br>
        </div> <hr>
        <div>
            <button type="submit"  name ="post" class="btn btn-default">Post</button><br>
        </div>
    </div>
</form>

<?php
include("../public/footer.php");
?>

1 个答案:

答案 0 :(得分:0)

我有权限问题,图片文件夹权限已更改。这解决了一切。谢谢!

相关问题