Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Everything is fine. No error is coming. Image name also stored in database perfectly but file is not moving in destination folder using move_uploaded_file function.

i don't know what to do. Please help me.

my code is:


link, $_POST['title']);
$body = mysqli_real_escape_string($db->link, $_POST['body']);
$category = mysqli_real_escape_string($db->link, $_POST['category']);
$author = mysqli_real_escape_string($db->link, $_POST['author']);
$tags = mysqli_real_escape_string($db->link, $_POST['tags']);

if(isset($_FILES['image'])){
$image = $_FILES['image']['name'];
$tmp_name = $_FILES['image']['tmp_name'];
$target= "images/";
}

if($title == '' || $body == '' || $category == '' || $author == ''){
$error = 'Please fill all required fields.';
}else{
$query = "INSERT INTO posts
(title, body, category, author, tags, image) VALUES('$title', '$body', $category, '$author', '$tags', '$image')";

$insert_row = $db->insert($query);


}
$upload = move_uploaded_file($tmp_name,$target.$image);
if ($upload){
$msg = "uploading file successfully.";
}else{
$msg = "there was a prob";
}
}
?>



select($query);
?>


<form role="form" method="post" action="add_post.php" enctype="multipart/form-data">

<label>Post title</label>
<input name="title" type="text" class="form-control" placeholder="Enter Title">



<label>Post Body</label>
<textarea name="body" class="form-control" placeholder="Enter Post Body"></textarea>



<label>Category</label>
<select name="category" class="form-control">

fetch_assoc()) : ?>

<option value=""></option>

</select>



<label>Author</label>
<input name="author" type="text" class="form-control" placeholder="Enter Author Name">




<label>Tags</label>
<input name="tags" type="text" class="form-control" placeholder="Enter Tags">



<label>Image</label>
<input name="image" type="file" class="form-control">



<input name="submit" type="submit" class="btn btn-default" value="Submit" />
Cancel



</form>




What I have tried:

i have tried this solution by changing target directories but nothing happen.

$target = $_SERVER['DOCUMENT_ROOT'] . '/images/';
$target = $target . basename($_FILES['image']['name']);
Posted
Updated 30-Sep-16 15:36pm

1 solution

Get the php enhanced manual here[^] if you don't have it already. The discussion on the move_uploaded_file page lists many things that can cause this to silently fail. Check them against your case.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900