我正在处理我的PHP代码(insert_post.php),我有两个错误:
**警告:move_uploaded_file(news_images / RaiderX.jpg):无法打开流:第106行的C:\ xampp \ htdocs \ my_cms \ admin \ insert_post.php中没有此类文件或目录
警告:move_uploaded_file():无法在第106行的C:\ xampp \ htdocs \ my_cms \ admin \ insert_post.php中将'C:\ xampp \ tmp \ php60F7.tmp'移动到'news_images / RaiderX.jpg' **
一切都很好,我可以看到数据(图像)正在进入我的mysql数据库,但我无法理解为什么会出现这两个错误。
这是代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
td, td {
padding:0px;
margin:0px;
}
</style>
<script src="//tinymce.cachefly.net/4.1/tinymce.min.js"></script>
<script>tinymce.init({selector:'textarea'});</script>
</head>
<body>
<form action="insert_post.php" method="post" enctype="multipart/form-data">
<table width="800" align="center" border="2">
<tr bgcolor="#F47302">
<td colspan="6" align="center"><h1>Insert New Post</h1></td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Title:</strong></td>
<td><input type="text" name="post_title" size="40"</td>
</tr>
<tr>
<td align="right"bgcolor="F47302" ><strong>Post Categories:</strong></td>
<td>
<select name="cat">
<option value="null">Select a Category</option>
<?php
include("../includes/database.php");
$get_cats = "select * from categories";
$run_cats = mysqli_query($con, $get_cats);
while ($cats_row=mysqli_fetch_array($run_cats)) {
$cat_id=$cats_row['cat_id'];
$cat_title=$cats_row['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Author:</strong></td>
<td><input type="text" name="post_author" size="40"</td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Keywords:</strong></td>
<td><input type="text" name="post_keywords" size="50"</td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Image:</strong></td>
<td><input type="file" name="post_image" size="50"</td>
</tr>
<tr>
<td align="right" bgcolor="F47302"><strong>Post Content:</strong></td>
<td><textarea name="post_content" rows="15" cols="60"></textarea></td>
</tr>
<tr>
<td colspan="6" align="center" bgcolor="F47302"><input type="submit" name="submit" value="Publish Now"</td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])) {
$post_title = $_POST['post_title'];
$post_date = date('m-d-y');
$post_cat = $_POST['cat'];
$post_author = $_POST['post_author'];
$post_keywords = $_POST['post_keywords'];
$post_image = $_FILES['post_image'] ['name'];
$post_image_tmp = $_FILES['post_image']['tmp_name'];
$post_content = $_POST['post_content'];
if($post_title=='' OR $post_cat=='null' OR $post_author=='' OR $post_keywords=='' OR $post_image=='' OR $post_content==''){
echo "<script>alert('Please fill in all the fileds')</script>";
exit();
}
else {
move_uploaded_file($post_image_tmp,"news_images/$post_image");
$insert_posts = "insert into posts (category_id,post_title,post_date,post_author,post_keywords,post_image,post_content) values ('$post_cat','$post_title','$post_date','$post_author','$post_keywords','$post_image','$post_content')";
$run_posts = mysqli_query($con,$insert_posts);
echo "<script>alert('Post Has been Published!')</script>";
echo "<script>window.open('index.php?insert_post','_self')</script>";
}
}
?>
答案 0 :(得分:0)
检查
$_FILES["post_image"]["error"]
首先出现任何类型的上传错误,这可能会让您更好地了解这种情况发生的原因并解决问题,这样您就不会在数据库中缓存丢失文件的信息