davidthom42 davidthom42 - 3 months ago 10
MySQL Question

Write File To folder in database using move_uploaded_file

So I am trying to upload an image in a post and post it. but when I use the the move_uploaded_file it doesnt write to the image folder. i have the permisions all good and ready but it still does not work. Any help would be great thanks.



<?php

if (isset($_POST['create_post'])) {
$post_title = $_POST['title'];
$post_author = $_POST['authror'];
$post_category_id= $_POST['post_category_id'];
$post_status = $_POST['post_status'];
$post_image = $_FILES['image']['name'];
$post_image_temp = $_FILES['image']['temp_name'];
$post_tags= $_POST['post_tags'];
$post_content = $_POST['post_content'];
$post_date = date('d-m-y');
$post_comment_count = 4;

move_uploaded_file($post_image_temp, "../images/$post_image");
}
?>

<form action = "" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="title"> Title</label>
<input type="text" class="form-control" name="title">
</div>

<div class="form-group">
<label for="Category"> Category</label>
<input type="text" class="form-control" name="category">
</div>

<div class="form-group">
<label for="Author"> Author</label>
<input type="text" class="form-control" name="author">
</div>

<div class="form-group">
<label for="post-status"> Status</label>
<input type="text" class="form-control" name="post_status">
</div>

<div class="form-group">
<label for="post_image"> Image</label>
<input type="file" name="image">
</div>

<div class="form-group">
<label for="post_tags"> Tags</label>
<input type="text" class="form-control" name="post_tags">
</div>

<div class="form-group">
<label for="post_content"> Content</label>
<textarea type="text" class="form-control" name="post_content" id="" cols="30" rows="10"></textarea>
</div>

<div class="form-group">
<input class="btn btn-primary" type="submit" name="create_post" value="publish post">
</div>

</form>




Answer

Check that

I Checked your code, the only change is $post_image_temp = $_FILES['image']['temp_name']; to $post_image_temp = $_FILES['image']['tmp_name']; the argument name is wrong

Check That, Probably this is the only Error, If the Same Error Occurs, post your Error, let me Know

<?php

if(isset($_POST['create_post'])){

     $post_title = $_POST['title'];
     $post_author = $_POST['authror'];
     $post_category_id= $_POST['post_category_id'];
     $post_status = $_POST['post_status'];
     $post_image = $_FILES['image']['name'];
     $post_image_temp = $_FILES['image']['tmp_name']; // this is change 
     $post_tags= $_POST['post_tags'];
     $post_content = $_POST['post_content'];
     $post_date = date('d-m-y');
     $post_comment_count = 4;
     move_uploaded_file($post_image_temp, "../images/$post_image");
}

?>

<form action = "" method="post" enctype="multipart/form-data">


    <div class="form-group">
        <label for="title"> Title</label>
        <input type="text" class="form-control" name="title">
    </div>

    <div class="form-group">
        <label for="Category"> Category</label>
        <input type="text" class="form-control" name="category">
    </div>

    <div class="form-group">
        <label for="Author"> Author</label>
        <input type="text" class="form-control" name="author">
    </div>

    <div class="form-group">
        <label for="post-status"> Status</label>
        <input type="text" class="form-control" name="post_status">
    </div>

    <div class="form-group">
        <label for="post_image"> Image</label>
        <input type="file" name="image">
    </div>

    <div class="form-group">
        <label for="post_tags"> Tags</label>
        <input type="text" class="form-control" name="post_tags">
    </div>
    <div class="form-group">
        <label for="post_content"> Content</label>
        <textarea type="text" class="form-control" name="post_content" id="" cols="30" rows="10"></textarea>
    </div>   
    <div class="form-group">
        <input class="btn btn-primary" type="submit" name="create_post" value="publish post">
    </div>

</form>