因此,我尝试使用 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/