新文件夹的move_uploaded_file错误

时间:2016-04-08 08:03:29

标签: php file file-upload upload server

我的服务器中有一个文件夹,我使用带有函数move_uploaded_file的php脚本上传文件。现在我在同一目录下创建了另一个文件夹,我想为它做同样的事情。

我已设置了读,写和执行的所有权限(777)。但是当我尝试将文件上传到新文件夹时,它会显示此错误。

" move_uploaded_file(/var/www/html/HV/tag/human_wal_r.wav):无法打开流:权限被拒绝"

我在这里发布我的代码。

    <?php

// Path to move uploaded files

 //$target_path = "";

 if(isset($_FILES['fileUp']['name'])){

    $fileName= basename($_FILES['fileUp']['name']);



    $pieces = explode("_", $fileName);

    $testStr= $pieces[0];


    echo "pieces   ". $testStr;
    if($testStr=="human")
    {
        $target_path = "/var/www/html/HV/tag/";

    }
    else
    {
        $target_path = "/var/www/html/HV/uploads/";
    }

    $target_path = $target_path . basename($_FILES['fileUp']['name']);
    echo $target_path."\n";

    try
    {
        if (!move_uploaded_file($_FILES['fileUp']['tmp_name'], $target_path)) {
            // make error flag true

            echo basename($_FILES['fileUp']['tmp_name'])."   ";
            echo "The file ". $target_path;
            echo "error!!!!!!";
        }
        else
        {
            echo "successfully uploaded!!";
        }

    }catch(Exception $e) {
        // Exception occurred. Make error flag true
        echo "exception::  ";
        echo $e;
    }

 }
 else
 {
    echo "no";
 }


?>

1 个答案:

答案 0 :(得分:0)

检查此路径权限/ var / www / html / HV / nd /,或检查这是否是正确的路径,因为在您的代码中我没有看到任何nd /目录作为目标路径