使用move_uploaded_file将文件写入数据库中的文件夹

时间:2016-08-17 17:06:32

标签: php mysql

所以我试图在帖子中上传图片并发布。但是当我使用move_uploaded_file时,它不会写入图像文件夹。我的所有权利都很好并准备就绪,但它仍然无效。任何帮助都会非常感谢。



<?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>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

检查

我检查了你的代码,唯一的变化是$ post_image_temp = $ _FILES ['image'] ['temp_name']; to $ post_image_temp = $ _FILES ['image'] ['tmp_name']; 参数名称错误

检查一下,可能这是唯一的错误,如果发生相同的错误,发布您的错误,让我知道

var moment = require('moment');

// Timestamp strings from API
var startDate = '2016-08-17T14:00:00-04:00';
var endDate = '2016-08-17T15:00:00-04:00';

// Create a range from the start and end dates
var range = moment().range(new Date(startDate), new Date(endDate));

// Get the current time
var currentTime = new Date();

// Does the current time fall within the range b/w the start and end dates
range.contains(currentTime);

答案 1 :(得分:0)

  1. 您只是假设上传永不失败。错误的假设
  2. 您只是假设移动呼叫永远不会失败。不好的假设。
  3. 一塌糊涂的事情就失败了。永远不要假设成功。总是假设失败,检查失败,并将成功视为一个惊喜。

    如果你有错误处理,你会被告知你的源文件不存在,因为:

    $post_image_temp = $_FILES['image']['temp_name'];
                                          ^----wrong
    

    它是tmp_name