php - 如何在我的计算机上启用文件夹以允许 php 将文件移动到其中?

标签 php mysql file-upload

因此,我尝试使用 PHP 将文件上传到文件夹中,但是图像没有出现。没有错误消息。我认为会出现一个错误,告诉我它们无法上传。

<?php

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

    $postTitle = trim($_POST['posttitle']);
    $postAuth = trim($_POST['postauthor']);
    $postStat = trim($_POST['poststatus']);
    $post_image = $_FILES['image']['name'];
    $post_image_temp = $_FILES['image']['tmp_name'];
    $postTags = trim($_POST['posttags']);
    $postDate = date('y-m-d');
    $postContent = trim($_POST['postcontent']);
    $postComCount = 4;

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

}

?>

<h1>Add New Post</h1>

<div class="col-xs-6">
<form action="" method="POST" enctype="multipart/form-data">
    <div class="form-group">
        <label for="posttitle">Post Title</label>
        <input type="text" name="posttitle" id="posttitle" class="form-control" maxlength="99"/>
    </div>
    <div class="form-group">
        <label for="postauthor">Post Author</label>
        <input type="text" name="postauthor" id="postauthor" class="form-control" maxlength="25"/>
    </div>
    <div class="form-group">
        <label for="postauthor">Post Status</label>
        <input type="text" name="poststatus" id="poststatus" class="form-control" maxlength="25"/>
    </div>
    <div class="form-group">
        <label for="postauthor">Post Image</label>
        <input type="file" name="image" id="image" class="form-control"/>
    </div>
    <div class="form-group">
        <label for="postauthor">Post Tags</label>
        <input type="text" name="posttags" id="posttags" class="form-control" maxlength="25"/>
    </div>
    <div class="form-group">
        <label for="postcontent">Post Content</label>
        <textarea type="text" name="postcontent" id="postcontent" class="form-control" rows="15" maxlength="10000"></textarea>
    </div>
    <button class="btn btn-primary" value="submit" name="postsubmit">Submit Post</button>
</form>
</div>

最佳答案

尝试改变

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

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

这是因为你只是传递了一个字符串 $post_image 而不是变量本身

关于php - 如何在我的计算机上启用文件夹以允许 php 将文件移动到其中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44233854/

相关文章:

javascript - 检查 javascript 数组中变量的位置

php - sed 将文件名视为模式?

php - 如何使用 tailf 正确编码 apache error.log?

php - laravel 5 collection pull 方法不打印任何内容

html - 验证文件上传

Django:上传文件并读取其内容以填充模型?

php - 在 Drupal 中如何获取 tnid 或翻译节点的节点 ID?

MySQL: bool 查询返回 true 如果用户没有设置 dnd 或者如果用户设置了 dnd 给定的 ID 必须是 friend

php - 上传的媒体 blob 在下载时被截断

javascript - 使用 Aurelia 将数据和文件发布到 ASP.NET webapi