繁体   English   中英

没有使用move_uploaded_file()这样的文件或目录

[英]No such file or directory using move_uploaded_file()

我正在处理我的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>";
                }
        }

?>

校验

$_FILES["post_image"]["error"]

首先针对任何类型的上传错误,这可以让您更好地了解这种情况的发生原因,并可以解决问题,因此您不会在数据库中缓存丢失文件的信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM