move_uploaded_file不起作用

时间:2014-02-23 15:18:54

标签: php

我正在尝试从HTML表单上传图片,但它不会将其上传到我的文件夹。

这是我的代码:

<form action="" method="post" enctype="multipart/form-data">
  <input type="file" name="image">
</form>
$post_image= $_FILES['image']['name'];
$image_tmp= $_FILES['image']['tmp_name'];
$location = $_SERVER['DOCUMENT_ROOT'] . "/images/".$post_image;
move_uploaded_file($image_tmp,$location);

这是文件夹结构:

root
   images ----> destination for upload
   includes
        admin ----> i am working here

我也尝试使用这样的路径,但它也没有用。

$location = "../../images".$post_image;

1 个答案:

答案 0 :(得分:0)

试试这个。请记住,您有权在测试文件夹中创建文件

<form action="" method="post" enctype="multipart/form-data">
  <input type="file" name="image">
  <input type='submit' />
</form>
<pre>
<?php
if(isset($_POST)){
    var_dump($_FILES);
    $post_image= $_FILES['image']['name'];
    $image_tmp= $_FILES['image']['tmp_name'];
    $location = $_SERVER['DOCUMENT_ROOT'] . "/images/".$post_image;
    move_uploaded_file($image_tmp,$location);
}
?>
</pre>