好吧,我正在尝试将图像上传到博客/上传/。脚本位置在admin_panel/add_post.php中。
<?php
if(isset($_POST['save'])){
$image = $_FILES['img']['name'];
$target_dir = "../blog/upload";
$target_file = $target_dir . basename($_FILES["img"]["name"]);
move_uploaded_file($_FILES['img']['tmp_name'],$target_file);
//get rid of all database operation and connection
}
?>
<form action="add_posts.php" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="img"><span class='name'>Select Image:</span></label>
<input type="file" class="form-control" name="img" id="img"
placeholder="Image">
</div>
这是我的URL:
localhost/sensive_blog/admin_panel/add_posts.php
我的项目文件夹层次结构:
admin_panel
->otherScript.php
->somefolder
->add_post.php
blog
->someotherscripts.php
->folder
在 $ target_dir 之后添加此内容,以检查文件夹是否存在
if (!is_dir($target_dir)) {
die('path not found);
}
最后我发现了我的错误。基本上是上传图像,但在错误的directory
上,它是带有怪异名称"upload[image_name]"
的博客。因此,我将一个前向斜线/
转到正确的directory
。然后魔术确实发生了。