文件没有上传到动态目录中的PHP

时间:2018-08-10 08:36:18

标签: php mysqli

我正在动态目录中上传多个文件,但显示错误。

  

警告:move_uploaded_file(1 / 1533889764_Koala.jpg):打开失败   流:中没有这样的文件或目录   C:\ xampp \ htdocs \ peacock \ contact.php,第48行

     

警告:move_uploaded_file():无法移动   将'C:\ xampp \ tmp \ php853E.tmp'转换为'1 / 1533889764_Koala.jpg'   C:\ xampp \ htdocs \ peacock \ contact.php,第48行

我的html代码:

<form method="post" action="" enctype="multipart/form-data">
Attach Files : <input type="file" name="cnt_img[]" multiple="multiple"><br>
<input type="submit" name="submit" value="Submit">
</form>

php代码:

if (isset($_REQUEST['submit'])) {

$insert_id  = mysqli_insert_id($conn);

    if ($_FILES['cnt_img']['name']!='') 

            $filefolder = mkdir($insert_id , 0777, true);


    {
        if(count($_FILES['cnt_img']['name']) > 0)
        {
            for($i=0; $i<count($_FILES['cnt_img']['name']); $i++)
            {
                $tmpFilePath = $_FILES['cnt_img']['tmp_name'][$i];
                    if($tmpFilePath != "")
                    {
                        $shortname = $_FILES['cnt_img']['name'][$i];
                        $filePath = $filefolder."/".time().'_'.$_FILES['cnt_img']['name'][$i];

                        if (move_uploaded_file($tmpFilePath, $filePath)) 
                        {
                            $files[] = $shortname;
                        }
                    }
            }
        }



    }

}

1 个答案:

答案 0 :(得分:-1)

     if ($_FILES['cnt_img']['name']!='') 

    {

        mkdir('contactus/'.$insert_id , 0777, true);

        if(count($_FILES['cnt_img']['name']) > 0)
        {
            for($i=0; $i<count($_FILES['cnt_img']['name']); $i++)
            {

                $tmpFilePath = $_FILES['cnt_img']['tmp_name'][$i];


                    if($tmpFilePath != "")
                    {
                        $shortname = $_FILES['cnt_img']['name'][$i];
                        $filePath = "contactus/".$insert_id."/".time().'_'.$_FILES['cnt_img']['name'][$i];

                        if (move_uploaded_file($tmpFilePath, $filePath)) 
                        {
                            $files[] = $shortname;
                        }
                    }
            }
        }



    }