2014-02-23 61 views
-1

我想从HTML表单上传图像,但它不会将其上传到我的文件夹。move_uploaded_file不起作用

这里是我的代码:

<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; 
+0

您是否具有对'images'文件夹的写入权限?或者说,您的网络服务器的用户是否具有写入权限? – Lix

+2

我希望你把''标签放在你的php代码中:) – 2014-02-23 15:21:53

+0

检查这一个http://stackoverflow.com/questions/5655859/move-uploaded-file-doesnt-work-no-error –

回答

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>